Skip to content

Instantly share code, notes, and snippets.

@yeyuguo
Forked from vvgomes/foo.js
Created October 30, 2020 03:42
Show Gist options
  • Save yeyuguo/30a281e6906995f5bb7960a74735811b to your computer and use it in GitHub Desktop.
Save yeyuguo/30a281e6906995f5bb7960a74735811b 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