3 ms·
> I have to open the damn documentation I don't know if you understand how lucky you are to be able to do this in the first place. Also, the "compact" method,
by isoskeles 7y ago
> I have to open the damn documentation
I don't know if you understand how lucky you are to be able to do this in the first place.
Also, the "compact" method, I don't know if this is the reason it gets its name in lodash etc., exists in the Ruby language and does the same thing.
- chmod775 7y ago> exists in the Ruby language and does the same thing. You just got lodash'd! Because the ruby method DOESN'T do the same thing. And this is precisely why you have to consult the documentation every single time you see something weird like that. The difference is that the ruby method doesn't remove stuff like "0" and "false", just "nil".
- ceejayoz 7y agoIt has the same fundamental function. JS just has the concept of "false-ish", which you'll likely already know as a JS developer.
- chmod775 7y agoThe ruby method removes "nil", not "false". The ruby method has absolutely nothing to do with false whatsoever, while lodash makes explicit reference to it. The ruby method is intended to just remove holes in arrays, not remove values. JavaScript has the concept of holes in arrays, but that's not what the lodash function is about. They're 2 different functions/methods with 2 different ideas behind them. They're absolutely not each other's equivalent in their respective language.
- dragonwriter 7y ago> It has the same fundamental function. No, it doesn't. > JS just has the concept of "false-ish", which you'll likely already know as a JS developer. Ruby has a concept of false-ish (which is narrower than JS’s), but Ruby’s “compact” isn't about false-ish-ness, Filtering out false-ish values is .select(&:itself), not .compact
- ceejayoz 7y agoMaybe my feelings here are colored by PHP being my primary lang, but I read both functions purpose as "remove the empty values from this array" with a language-level difference on what "empty" is defined as. PHP's "empty" includes both nulls and false-y values. Whether you want to call it the "same" function or "similar" function, lodash's excellent docs reveal its functionality quite handily if someone's confused by it.
- isoskeles 7y agoHaha, would you look at that. Still, I prefer having documentation over the possible scenario where I have a few undocumented functions created by other developers for whatever reason. Maybe multiple functions do the same thing. Not to say this is the only alternative, but it is the more common alternative I've seen years ago, and it's a certain type of hell.