Given the array nums
consisting of 2n
elements in the form [x1,x2,...,xn,y1,y2,...,yn]
.
Return the array in the form [x1,y1,x2,y2,...,xn,yn]
.
/**
* @param {number[]} nums
* @param {number} n
* @return {number[]}
*/
const nums = [2,5,1,3,4,7];
const n = 3;
var shuffle = function(nums, n) {
const a=[];
const b=[];
const c=[];
for(let i=n;i<n*2;i++){
a.push(nums[i]);
}
for(let i=0;i<n;i++){
b.push(nums[i]);
}
/*console.log(a);
console.log(b);*/
for(let i=0;i<n;i++){
c.push(b[i]);
c.push(a[i]);
}
console.log(c);
return c;
};