DEV Community

Discussion on: 1 line of code: How to clean an Array of "falsy" items

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ • Edited
const cleanFalsy = arr => arr.filter(i=>i)
Enter fullscreen mode Exit fullscreen mode

This is almost twice as fast on Firefox. On Chrome, the two methods are similarly efficient with i=>i being ever so slightly quicker. Performance link

I guess this is because allowing the internal Boolean coercion to do its thing is faster than explicitly doing it yourself.

Collapse
 
martinkr profile image
Martin Krause

Thank you for the effort of setting up the performance comparison and sharing with us. I amended he article on updated the code.

Cheers!