function pushZeroesToEnd(a) { const upZeroArray = a.filter(n => n > 0); const zeroArray = a.filter(n => n == 0); return upZeroArray.concat(zeroArray); }
let arr = [4, 5, 1, 5, 2, 5, 0, 0, 0, 0, 0]; pushZeroesToEnd(arr);
IDK if the best implementation, but its faster and easy, specially for a work break ;)
glad it could be a good work break!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
function pushZeroesToEnd(a) {
const upZeroArray = a.filter(n => n > 0);
const zeroArray = a.filter(n => n == 0);
return upZeroArray.concat(zeroArray);
}
let arr = [4, 5, 1, 5, 2, 5, 0, 0, 0, 0, 0];
pushZeroesToEnd(arr);
IDK if the best implementation, but its faster and easy, specially for a work break ;)
glad it could be a good work break!