Lately I find myself using associative arrays (or hastables) more and more in my applications (advantages being lookup speed, duplicate removal etc).
Here is typical code taken from my application -
var parent1 = { id: 5, name: 'parent 1'}, parent2 = { id: 10, name: 'parent 2'};
var children = [{id: 1, parent: parent1}, {id: 2, parent: parent1}, {id: 3, parent: parent1}, {id: 4, parent: parent2}]
var addToHash = function (hashObj, child) {
var parent = child.parent;
hashObj[parent.id] = parent;
return hashObj;
};
var uniqueParents = R.reduce(addToHash, {}, children);
At the moment I use the Ramda reduce function.
Question - Is there a better (more succinct) way to do this either with Ramda, another 3rd party lib or simply in plain vanilla Javascript?