shuffle the array

Run Settings
LanguageJavaScript
Language Version
Run Command
// https://leetcode.com/problems/shuffle-the-array/ const nums = [2,5,1,3,4,7], n = 3; // 2,5,1 | 3,4,7 const shuffle = (nums, n) => { let result = []; for (let i = 0; i < n; i++) { result.push(nums[i]); result.push(nums[n+i]); } return result; } //const shuffle2 = (nums, n) => { // for (let i=0; i<n; i++) { // const temp = nums[n+i]; // const temp2 = nums[i+1]; // nums[i+1] = temp; // nums[n+i] = temp2; // } // return nums; //} console.log(shuffle(nums, n));
Editor Settings
Theme
Key bindings
Full width
Lines