Move Zeroes
LeetCode題目: 283. Move Zeroes
My solution:
/**
* @param {number[]} nums
* @return {void} Do not return anything, modify nums in-place instead.
*/
Array.prototype.findIndexAll = function(fn) {
let indexList = [];
this.forEach((item, idx) => fn(item) === true && indexList.push(idx));
return indexList;
}
let moveZeroes = nums => nums.findIndexAll(v=>v===0).reverse().forEach(idx => {
nums.splice(idx, 1);
nums.push(0)
});