i need to put all items that equals zero att the end of the array, i used a classic permutation code to do that, it works but it does not continu the comparison untill the end.
function moveZeros(arr) {
var permut = 0;
var i=0;
while( i <= arr.length) {
if(arr[i] === 0) {
permut = arr[i];
arr[i] = arr[i+1]
arr[i+1] = "0";
}
i++
}
return arr.join()
}
console.log(moveZeros([1,2,0,1,0,1,0,3,0,1]))
// i have this : 1,2,1,0,1,0,3,0,1,0
// But Need to have this result : 1, 2, 1, 1, 3, 1, 0, 0, 0, 0