{"ScriptPreparationCode":"var arraySmall = new Array(12).map((v,i)=\u003Ei);\r\nvar arrayMedium = new Array(1200).map((v,i)=\u003Ei);\r\nvar arrayLong = new Array(120000).map((v,i)=\u003Ei);\r\n","TestCases":[{"Name":"Recursive Small","Code":"const rotateArrayRecursive = (numberRotations, array) =\u003E {\r\n const n = Math.abs(numberRotations);\r\n if (n === 0) {\r\n return [...array];\r\n } else if (n === 1) {\r\n return [array[array.length], ...array.slice(0,array.length-1) ];\r\n } else {\r\n return rotateArrayRecursive(1, rotateArrayRecursive(n - 1, array));\r\n }\r\n}\r\n\r\nrotateArrayRecursive(4,arraySmall);","IsDeferred":false},{"Name":"Recursive Medium","Code":"const rotateArrayRecursive = (numberRotations, array) =\u003E {\r\n const n = Math.abs(numberRotations);\r\n if (n === 0) {\r\n return [...array];\r\n } else if (n === 1) {\r\n return [array[array.length], ...array.slice(0,array.length-1) ];\r\n } else {\r\n return rotateArrayRecursive(1, rotateArrayRecursive(n - 1, array));\r\n }\r\n}\r\n\r\nrotateArrayRecursive(456,arrayMedium);","IsDeferred":false},{"Name":"Recursive Long","Code":"const rotateArrayRecursive = (numberRotations, array) =\u003E {\r\n const n = Math.abs(numberRotations);\r\n if (n === 0) {\r\n return [...array];\r\n } else if (n === 1) {\r\n return [array[array.length], ...array.slice(0,array.length-1) ];\r\n } else {\r\n return rotateArrayRecursive(1, rotateArrayRecursive(n - 1, array));\r\n }\r\n}\r\n\r\nrotateArrayRecursive(45678,arrayLong);","IsDeferred":false},{"Name":"Direct Small","Code":"const rotateArrayDirect = (desiredRotation, array) =\u003E {\r\n\r\n // Size of the array, needed later on\r\n const arrayLength = array.length;\r\n\r\n // Ensure we rotate by the right amount, whatever the desiredRotation value\r\n // This formula is needed because JS % modulo operator returns negative output for negative inputs\r\n const effectiveRotation = ((desiredRotation % arrayLength) \u002B 2 * arrayLength) % arrayLength;\r\n\r\n // Cut the array in two parts and merge them\r\n return [\r\n ...array.slice(effectiveRotation, arrayLength),\r\n ...array.slice(0, effectiveRotation)\r\n ];\r\n}\r\n\r\nrotateArrayDirect(4,arraySmall);","IsDeferred":false},{"Name":"Direct Medium","Code":"const rotateArrayDirect = (desiredRotation, array) =\u003E {\r\n\r\n // Size of the array, needed later on\r\n const arrayLength = array.length;\r\n\r\n // Ensure we rotate by the right amount, whatever the desiredRotation value\r\n // This formula is needed because JS % modulo operator returns negative output for negative inputs\r\n const effectiveRotation = ((desiredRotation % arrayLength) \u002B 2 * arrayLength) % arrayLength;\r\n\r\n // Cut the array in two parts and merge them\r\n return [\r\n ...array.slice(effectiveRotation, arrayLength),\r\n ...array.slice(0, effectiveRotation)\r\n ];\r\n}\r\n\r\nrotateArrayDirect(456,arrayMedium);","IsDeferred":false},{"Name":"Direct Long","Code":"const rotateArrayDirect = (desiredRotation, array) =\u003E {\r\n\r\n // Size of the array, needed later on\r\n const arrayLength = array.length;\r\n\r\n // Ensure we rotate by the right amount, whatever the desiredRotation value\r\n // This formula is needed because JS % modulo operator returns negative output for negative inputs\r\n const effectiveRotation = ((desiredRotation % arrayLength) \u002B 2 * arrayLength) % arrayLength;\r\n\r\n // Cut the array in two parts and merge them\r\n return [\r\n ...array.slice(effectiveRotation, arrayLength),\r\n ...array.slice(0, effectiveRotation)\r\n ];\r\n}\r\n\r\nrotateArrayDirect(45678,arrayLong);","IsDeferred":false},{"Name":"Juggling small","Code":"const gcd = (a, b) =\u003E {\r\n\tif(b==0){\r\n return a; \r\n }else{\r\n return gcd(b, a%b); \r\n }\r\n}\r\n\r\nconst rotateArrayJuggling = (desiredRotation, array) =\u003E {\r\n const n = array.length;\r\n let temp = null;\r\n let j = null;\r\n let k = null;\r\n const gcdResult = gcd(desiredRotation, n);\r\n for (let i = 0; i \u003C gcdResult; i\u002B\u002B){\r\n \ttemp = array[i];\r\n j = i;\r\n while (true){\r\n \tk = j \u002B desiredRotation;\r\n \tif (k \u003E= n){\r\n \tk = k - n; \r\n }\r\n \tif (k== i){\r\n \t\tbreak; \r\n }\r\n \tarray[j] = array[k];\r\n \tj = k;\r\n }\r\n \tarray[j] = temp;\r\n }\r\n return array;\r\n}\r\n\r\nrotateArrayJuggling(4,arraySmall);","IsDeferred":false},{"Name":"Juggling medium","Code":"const gcd = (a, b) =\u003E {\r\n\tif(b==0){\r\n return a; \r\n }else{\r\n return gcd(b, a%b); \r\n }\r\n}\r\n\r\nconst rotateArrayJuggling = (desiredRotation, array) =\u003E {\r\n const n = array.length;\r\n let temp = null;\r\n let j = null;\r\n let k = null;\r\n const gcdResult = gcd(desiredRotation, n);\r\n for (let i = 0; i \u003C gcdResult; i\u002B\u002B){\r\n \ttemp = array[i];\r\n j = i;\r\n while (true){\r\n \tk = j \u002B desiredRotation;\r\n \tif (k \u003E= n){\r\n \tk = k - n; \r\n }\r\n \tif (k== i){\r\n \t\tbreak; \r\n }\r\n \tarray[j] = array[k];\r\n \tj = k;\r\n }\r\n \tarray[j] = temp;\r\n }\r\n return array;\r\n}\r\n\r\nrotateArrayJuggling(456,arrayMedium);","IsDeferred":false},{"Name":"Juggling large","Code":"const gcd = (a, b) =\u003E {\r\n\tif(b==0){\r\n return a; \r\n }else{\r\n return gcd(b, a%b); \r\n }\r\n}\r\n\r\nconst rotateArrayJuggling = (desiredRotation, array) =\u003E {\r\n const n = array.length;\r\n let temp = null;\r\n let j = null;\r\n let k = null;\r\n const gcdResult = gcd(desiredRotation, n);\r\n for (let i = 0; i \u003C gcdResult; i\u002B\u002B){\r\n \ttemp = array[i];\r\n j = i;\r\n while (true){\r\n \tk = j \u002B desiredRotation;\r\n \tif (k \u003E= n){\r\n \tk = k - n; \r\n }\r\n \tif (k== i){\r\n \t\tbreak; \r\n }\r\n \tarray[j] = array[k];\r\n \tj = k;\r\n }\r\n \tarray[j] = temp;\r\n }\r\n return array;\r\n}\r\n\r\nrotateArrayJuggling(45678,arrayLong);","IsDeferred":false}]}