{"ScriptPreparationCode":null,"TestCases":[{"Name":"Native Methods","Code":"// Params:\r\nvar arr = [1, 2, 3, 4];\r\nconst index = 3;\r\nconst newItem = 5;\r\n\r\n// Steps:\r\n// 1. Create new array from the original one at given index\r\nlet start = arr.slice(0, index);\r\n\r\n// 2. Add new item to the copy\r\nstart.push(newItem);\r\n\r\n// 3. Get the rest of the original array\r\nlet end = arr.slice(index);\r\n\r\n// 4. Save result\r\narr = start.concat(end)\r\n\r\n// 5. Print the merged array\r\nconsole.log(arr);","IsDeferred":false},{"Name":"Custom Loop","Code":"// Params:\r\nvar arr = [1, 2, 3, 4];\r\nconst index = 3;\r\nconst newItem = 5;\r\n\r\nvar temp;\r\nvar newArr = [...arr];\r\nfor(var i = index; i \u003C arr.length; i\u002B\u002B){\r\n if(temp === undefined){\r\n temp = newArr[i];\r\n }else{\r\n var t = newArr[i];\r\n newArr[i] = temp;\r\n temp = t;\r\n }\r\n}\r\nnewArr[arr.length] = temp;\r\nnewArr[index] = newItem;\r\narr = [...newArr];\r\n\r\nconsole.log(arr);","IsDeferred":false},{"Name":"Other Custom Loop","Code":"// Params:\r\nvar arr = [1, 2, 3, 4];\r\nconst index = 3;\r\nconst newItem = 5;\r\n\r\n// Steps:\r\n// 1. Create new array from the original one at given index\r\nlet copy = [];\r\nfor (let i = 0; i \u003C index; i\u002B\u002B) {\r\n copy[copy.length] = arr[i];\r\n}\r\n\r\n// 2. Add new item to the copy\r\ncopy[index] = newItem;\r\n\r\n// 3. Get the rest of the original array\r\nlet rest = [];\r\nfor (let i = index; i \u003C arr.length; i\u002B\u002B) {\r\n rest[rest.length] = arr[i];\r\n}\r\n\r\n// 4. Merge the two arrays\r\nfor (let i = 0; i \u003C rest.length; i\u002B\u002B) {\r\n copy[copy.length] = rest[i];\r\n}\r\n\r\n// 5. Save new arr\r\narr = [...copy];\r\n\r\n// 6. Print the merged array\r\nconsole.log(arr);","IsDeferred":false}]}