DEV Community

Discussion on: Javascript Array Condensing

Collapse
 
matgott profile image
matgott

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 ;)

Collapse
 
lehmannsystems profile image
Mike

glad it could be a good work break!