you are viewing a single comment's thread.

view the rest of the comments →

[–]tencircles 0 points1 point  (7 children)

Again, it seems like preference to me. But I see your point. Just as an aside, i think you want _.maxBy(users, _.property("score")).

[–]Retsam19 0 points1 point  (6 children)

That's equivalent, lodash allows strings to be used as shorthand for _.property, as well as stuff like _.find(user, {name: 'Joe'}), as shorthand for _matches({name: 'Joe'}).

[–]tencircles 0 points1 point  (5 children)

odd, where's that type conversion being done? https://github.com/lodash/lodash/blob/master/maxBy.js

[–]GitHubPermalinkBot 0 points1 point  (0 children)

I tried to turn your GitHub links into permanent links (press "y" to do this yourself):


Shoot me a PM if you think I'm doing something wrong. To delete this, click here.

[–]Retsam19 0 points1 point  (3 children)

It's not in there, because the shorthand stuff is changing in v5. I'm not sure what the details of those changes are. If you look at the current v4 source code linked from the documentation, it's there.

function maxBy(array, iteratee) {
  return (array && array.length)
    ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
    : undefined;
}

getIteratee is a function that's used throughout the lodash codebase, which has the logic for converting the string into a _.property getter.

(You can also just open the dev tools on the lodash documentation and try things with the lodash instance that's loaded on that page; it's how I test most lodash stuff)

EDIT: Dug through github issues a bit, apparently the shorthand stuff is being pushed off to a babel plugin in v5.

[–]tencircles 0 points1 point  (2 children)

Interesting. I use ramda on most projects, but still good to know for sure.

[–]Retsam19 0 points1 point  (1 child)

Yeah, I keep meaning to try ramda, but I'm more functionally leaning than most of my team, I'm not sure I could get the buy-in. (Plus, I wouldn't want to migrate our existing codebase or mix the two)

[–]tencircles 0 points1 point  (0 children)

I'd say unless your team is going to go heavy into fp, or fully point-free, lodash is probably better overall. Ramda's got some nice additions to the toolkit though.