Skip to content

Instantly share code, notes, and snippets.

@vvgomes
Last active August 10, 2021 18:10
Show Gist options
  • Star 41 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save vvgomes/451ea5ca2c65e87c92e4 to your computer and use it in GitHub Desktop.
Save vvgomes/451ea5ca2c65e87c92e4 to your computer and use it in GitHub Desktop.
Ramda vs Lodash
var _ = require("lodash");
var R = require("ramda");
var companies = [
{ name: "tw", since: 1993 },
{ name: "pucrs", since: 1930 },
{ name: "tw br", since: 2009 }
];
var r1 = _(companies).chain()
.filter(function(c) {
return c.name.split(" ")[0] === "tw";
})
.map(function(c) {
return {
name: c.name.toUpperCase(),
since: c.since
};
})
.sortBy(function(c) {
return c.since;
})
.reverse()
.value();
console.log("with lodash:", r1);
var r2 = R.compose(
R.reverse,
R.sortBy(R.prop("since")),
R.map(R.over(R.lensProp("name"), R.toUpper)),
R.filter(R.where({ name: R.test(/^tw/) }))
)(companies);
console.log("with ramda:", r2);
@enoh-barbu
Copy link

Oh, I wasn't aware of this comparison.

@qjnz
Copy link

qjnz commented Jan 12, 2021

how about from performance perspective? anyone has done it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment