Here's one way of doing it. In the example I assumed that the first value was the patientId
and the second value the conditionId
. The code keeps track of grouping keys (concatenation of the patientId
and the conditionId
) that were seen already and ignores them.
var countMap = [
[1, 'c1'],
[1, 'c1'],
[2, 'c1'],
[2, 'c2']
].reduce(function (r, v) {
var condition = v[1],
groupKey = v[0] + condition;
if (!r.seen[groupKey]) {
r.seen[groupKey] = true;
r.count[condition] = (r.count[condition] || 0) + 1;
}
return r;
}, {seen: {}, count: {}}).count;
countMap.c1; //2
countMap.c2; //1
I do not know about crossfilter or dc.js, that's why I gave you a vanilla JS solution.