function moveZeros(arr) {let zeros = [];let nonZeros = [];
}
let arr = [0, 1, 0, 3, 12];let rearrangedArr = moveZeros(arr);console.log(rearrangedArr); // [1, 3, 12, 0, 0]
function moveZeros(arr) {
for (let i = 0; i < arr.length; i++) {let zeros = [];
let nonZeros = [];
if (arr[i] === 0) {
zeros.push(0);
} else {
nonZeros.push(arr[i]);
}
}
return nonZeros.concat(zeros);
}
let arr = [0, 1, 0, 3, 12];
let rearrangedArr = moveZeros(arr);
console.log(rearrangedArr); // [1, 3, 12, 0, 0]