Skip to content

Instantly share code, notes, and snippets.

@rnewson
Created August 19, 2014 12:05
Show Gist options
  • Save rnewson/27de51b81ad0541e8a94 to your computer and use it in GitHub Desktop.
Save rnewson/27de51b81ad0541e8a94 to your computer and use it in GitHub Desktop.
12:37 <Baz___> Specifically, I have ratings ({ accountID, itemID, rating }) and am trying to find out how many times pairs of users rated the same items: [{ accountID1, accountID2, numTimesRatedSameItem }]
map:
emit([doc.itemID, doc.accountID]);
reduce:
var permute = function(arr) {
// return an array of every pair of values in arr,
// each array item is sorted.
};
if (!rereduce) {
var result = [];
var items = unique values from all keys[0];
for (var item in items) {
var accountsForItem = sorted array of accountID's for this item
for (var permutation in permute(accountsForItem)) {
emit(permutation, 1);
}
}
return result;
} else {
return sum(values);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment