JSFiddle - React, Tailwind, and code Playground
by Vladimir
JavaScript
function putZeroToTheEnd(arr) {
var zeroArray = [];
var nonZeroArray = [];
arr.forEach(function(el) {
if(el === 0) {
zeroArray.push(el);
} else {
nonZeroArray.push(el);
}
});
return nonZeroArray.concat(zeroArray);
}
console.log('putZeroToTheEnd([1, 0, 0, 0, 2, 3] ) == ' + putZeroToTheEnd([1, 0, 0, 0, 2, 3] ));
console.log('putZeroToTheEnd([1, 0, 3, 0]) == ' + putZeroToTheEnd([1, 0, 3, 0]));
console.log('putZeroToTheEnd([1, 3, 0, 0, 0]) == ' + putZeroToTheEnd([1, 3, 0, 0, 0]));