MCPcopy Create free account
hub / github.com/chetannada/Javascript-Practice / createTargetArray

Function createTargetArray

2023_year/March_2023/index19.js:8–14  ·  view source on GitHub ↗
(nums, index)

Source from the content-addressed store, hash-verified

6 * @return {number[]}
7 */
8var createTargetArray = function(nums, index) {
9 let target = []; // initialize an empty array
10 for(let i=0; i<nums.length; i++){ // loop through the every element of an array
11 target.splice(index[i], 0, nums[i]); // add element to the target as per index
12 }
13 return target; // return the target array
14};
15
16console.log(createTargetArray([0,1,2,3,4],[0,1,2,2,1])); // [0,4,1,3,2]
17

Callers 1

index19.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected