Javascript Array Move zero element to tail

Description

Javascript Array Move zero element to tail


var moveZeroes = function(nums) {
  for (var i = nums.length - 1; i >= 0; i--){
    console.log(i);/*from w  ww .  java2  s. co m*/
    if(nums[i] === 0){
      nums.splice(i, 1);
      nums.push(0);
    }  
  }

  return nums;
};

console.log(moveZeroes([0,1,0,3,12]));



PreviousNext

Related