{"ScriptPreparationCode":"var arr = [1,2,3,4];","TestCases":[{"Name":"splice","Code":"function arrayMove(arr, oldIndex, newIndex) {\r\n const copiedArr = [...arr];\r\n const length = copiedArr.length;\r\n \r\n if (oldIndex !== newIndex \u0026\u0026 length \u003E oldIndex \u0026\u0026 length \u003E newIndex) {\r\n copiedArr.splice(newIndex, 0, copiedArr.splice(oldIndex, 1)[0]);\r\n }\r\n \r\n return copiedArr;\r\n}\r\n\r\narrayMove(arr, 0, 3)","IsDeferred":false},{"Name":"flatMap","Code":"function arrayMove(arr, oldIndex, newIndex) {\r\n const length = arr.length;\r\n const itemToMove = arr[oldIndex]\r\n\r\n if (oldIndex === newIndex || oldIndex \u003E length || newIndex \u003E length) {\r\n return arr;\r\n }\r\n\r\n return arr.flatMap((item, index) =\u003E {\r\n if (index === oldIndex) return [];\r\n if (index === newIndex) return oldIndex \u003C newIndex ? [item, itemToMove] : [itemToMove, item];\r\n return item;\r\n })\r\n}\r\n\r\narrayMove(arr, 0, 3)","IsDeferred":false},{"Name":"reduce","Code":"function arrayMove(arr, oldIndex, newIndex) {\r\n const length = arr.length;\r\n const itemToMove = arr[oldIndex]\r\n\r\n if (oldIndex === newIndex || oldIndex \u003E length || newIndex \u003E length) {\r\n return arr;\r\n }\r\n\r\n return arr.reduce((acc, item, index) =\u003E {\r\n if (index === oldIndex) return acc;\r\n if (index === newIndex) return oldIndex \u003C newIndex ? [...acc, item, itemToMove] : [...acc, itemToMove, item];\r\n return [...acc, item];\r\n }, [])\r\n}\r\n\r\narrayMove(arr, 0, 3)","IsDeferred":false}]}