Hacker News new | ask | show | jobs
by ilitirit 4155 days ago
Some code that I've written using Ramda.js:

  var predicateListFunc = function(props) { return R.allPredicates(R.map(R.curry(R.eqProps), props)); }
  var compareProperties = R.unapply(predicateListFunc);

  var mergeLists = R.unionWith(compareProperties("Property1", "Property2"));
  var groupById = R.groupBy(R.prop("Property1"));
  var getGroups = R.compose(R.toPairs, groupById, mergeLists);

  var groups = getGroups(list1, list2);

With this code I can merge any two lists (list1 and list2) on any two properties (Property1 and Property2), and then group the result. I use this to synchronize client and server data.

I don't know if this answers your question, since I wrote in about an hour of learning Ramda.js, and there might be an easier way of doing it.

Here's a fiddle:

http://jsfiddle.net/Gk6uu/10/