3 ms·
The thing is that the JavaScript version is often more readable than the lodash one (unless you have a lot of experience with lodash of course). For example:
by olalonde 4y ago
The thing is that the JavaScript version is often more readable than the lodash one (unless you have a lot of experience with lodash of course).
For example:
_.compact(array)
vs
array.filter(value => !!value);
Most JavaScript programmers will immediately know what `array.filter(value => !!value)` does but many will have to lookup the lodash documentation to understand what `_.compact(array)` does.
- amadeuspagel 4y agoThat's a good example. I looked at the first example "chunk" where the replacement is just a "chunk" function in javascript, and I asked myself what the purpose of this is, why I would copy-and-paste this chunk function rather then importing it from lodash. I think this site would be much better if it only included examples where the vanilla JS version is actually more readable.
- hajile 4y agoBut if you chain both of those, the `.compact()` will use Lodash iterators while the builtin will repeatedly iterate over the array.