Coding Challenge: Move all zeros at the end of the Array

Question: Move all zeros at the end of the array

Answer:

function pushZerosToEnd(arr) {

let count = 0;

for (let i = 0; i < arr.length; i++) {

if (arr[i] !== 0) {

arr[count++] = arr[i];

}

}

while (count < arr.length) arr[count++] = 0;

return arr;

}

pushZerosToEnd([0, 1, 2, 0, 3, 0, 5, 6]);

Try it yourself: