News for hackers. Stuff that matters.
Re:You-Dont-Need-Lodash-Underscore by irrational on Friday August 09, 2019 @02:03PM (#20656842)
>This does not need any documentation or comment.

I honestly have no more clue what const cleanInput = input.filter(elem => !!elem); means than const cleanInput = _.compact(input); without going to the documentation.

What you meant to say is "This does not need any documentation or comment for myself, because I have already memorized what all the parts of this line of code mean, whereas I have not yet memorized what _.compact means."

Re:You-Dont-Need-Lodash-Underscore by marmada on Friday August 09, 2019 @07:08PM (#20658936)
There's nothing to memorize here, or there shouldn't be, because "filter" is a standard array function in JS that I imagine most JS developers have encountered.

Knowing how "filter" works is valuable because now you can use that knowledge in the future on any project that uses JS, unlike "_.compact" which is only applicable in projects that use lodash. You can be relatively confident that you can write "filter(elem => <some function>)" and that other developers will know what "filter" is doing.

The second part is more tricky, but still useful.

The !! operator is just two "!" operators. That's pretty normal too. The first "!" converts an object/number/whatever into the opposite of its boolean value. The second "!" negates the first boolean, thus turning the opposite of the boolean value into the object's original boolean value.

Even if figuring this out on your own is slightly more difficult, it gives you valuable insight into the language (JS is very dynamically-typed and the not operator can cast objects to booleans), which will help you write better/safer/more concise/clearer code in the future.

Re:You-Dont-Need-Lodash-Underscore by chmod775 on Friday August 09, 2019 @02:09PM (#20656893)
The difference is that one thing uses JavaScript fundamentals that (except for the arrow function shorthand) have been part of the language since JavaScript 1.6 and the other is just some random library.