-
-
Save heanfig/7e363c2fdf7d307de8ffc7d60dad9cce to your computer and use it in GitHub Desktop.
Ramda vs Lodash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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