DEV Community

loading...

Discussion on: JavaScript Challenge 3: Remove Zeroes

Collapse
webit profile image
webit

How about:

const arr = [7, 2, 3, 0, 4, 6, 0, 0, 13, 0, 78, 0, 0, 19, 14];

const nextArr = [...arr.filter(Boolean), ...arr.filter((v) => !v)];
Enter fullscreen mode Exit fullscreen mode
Collapse
albertomontalesi profile image
AlbertoM Author

Nice one line solution!