Given an integer array and a number n, move all of thens to the end of the array while maintaining the relative order of the non-ns. Bonus: do this without making a copy of the array!
$ moveNums([0,2,0,3,10], 0)
$ [2,3,10,0,0]| function moveNums(arr, t) => { | |
| for (let i = 0; i < arr.length; i++) { | |
| if (arr[i] === t) { | |
| arr.splice(i, 1); | |
| arr.push(t); | |
| } | |
| } | |
| return arr; | |
| } |
Given an integer array and a number n, move all of thens to the end of the array while maintaining the relative order of the non-ns. Bonus: do this without making a copy of the array!
$ moveNums([0,2,0,3,10], 0)
$ [2,3,10,0,0]