{"ScriptPreparationCode":null,"TestCases":[{"Name":"Cut and move slices with .slice()","Code":"const array1 = [\u0022a\u0022,\u0022b\u0022,\u0022c\u0022,\u0022x\u0022,\u0022d\u0022];\r\nconst array2 = [\u0022a\u0022,\u0022b\u0022,\u0022c\u0022,\u0022d\u0022,\u0022x\u0022];\r\nconst array3 = [\u0022a\u0022,\u0022x\u0022,\u0022b\u0022,\u0022c\u0022,\u0022d\u0022,\u0022e\u0022];\r\nconst array4 = [\u0022x\u0022,\u0022a\u0022,\u0022b\u0022,\u0022c\u0022,\u0022d\u0022,\u0022e\u0022];\r\n\r\nfunction reorderArray(array,itemIndex,newPosition) {\r\n\r\n const toFront = itemIndex \u003E newPosition ? true : false;\r\n\r\n const a = toFront ? array.slice(0,newPosition) : array.slice(0,itemIndex);\r\n const b = toFront ? array.slice(newPosition,itemIndex) : array.slice(itemIndex,itemIndex\u002B1);\r\n const c = toFront ? array.slice(itemIndex,itemIndex\u002B1) : array.slice(itemIndex\u002B1,newPosition\u002B1);\r\n const d = toFront ? array.slice(itemIndex\u002B1) : array.slice(newPosition\u002B1);\r\n\r\n return [].concat(a, c, b, d);\r\n}\r\n\r\nconst a = reorderArray(array1,3,1);\r\nconst b = reorderArray(array2,4,0);\r\nconst c = reorderArray(array3,1,3);\r\nconst d = reorderArray(array4,0,1);\r\nconst e = reorderArray(array4,0,0);\r\n\r\nconsole.log(a,b,c,d,e);","IsDeferred":false},{"Name":"Mutate with .splice()","Code":"const array1 = [\u0022a\u0022,\u0022b\u0022,\u0022c\u0022,\u0022x\u0022,\u0022d\u0022];\r\nconst array2 = [\u0022a\u0022,\u0022b\u0022,\u0022c\u0022,\u0022d\u0022,\u0022x\u0022];\r\nconst array3 = [\u0022a\u0022,\u0022x\u0022,\u0022b\u0022,\u0022c\u0022,\u0022d\u0022,\u0022e\u0022];\r\nconst array4 = [\u0022x\u0022,\u0022a\u0022,\u0022b\u0022,\u0022c\u0022,\u0022d\u0022,\u0022e\u0022];\r\n\r\nfunction arraymove(arr, fromIndex, toIndex) {\r\n const element = arr[fromIndex];\r\n arr.splice(fromIndex, 1);\r\n arr.splice(toIndex, 0, element);\r\n}\r\n\r\narraymove(array1,3,1);\r\nconsole.log(array1);\r\narraymove(array2,4,0);\r\nconsole.log(array2);\r\narraymove(array3,1,3);\r\nconsole.log(array3);\r\narraymove(array4,0,1);\r\nconsole.log(array4);\r\narraymove(array4,0,0);\r\nconsole.log(array4);","IsDeferred":false}]}