Skip to content

Instantly share code, notes, and snippets.

@cweekly
Forked from vvgomes/foo.js
Created April 24, 2020 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cweekly/08554ba8750e968f34e1bef3dace9eaf to your computer and use it in GitHub Desktop.
Save cweekly/08554ba8750e968f34e1bef3dace9eaf 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment