{"ScriptPreparationCode":null,"TestCases":[{"Name":"For-loop approach test","Code":"// Params:\r\nconst 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. Print the merged array\r\nconsole.log(copy);","IsDeferred":false},{"Name":"Native functions test","Code":"// Params:\r\nconst 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. Print the merged array\r\nconsole.log(start.concat(end));","IsDeferred":false}]}