vincentbollaert
9/3/2015 - 12:50 PM

Ramda vs Lodash

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);