var picker = function( results, size ){ var combined = []; var num_results = 0; for (var i=0; i 0) ? sort_by_score(combined) : combined; }; var dedup = function(arr) { var unique_ids = []; return arr.filter(function(item, pos) { if (unique_ids.indexOf(item.name.default) === -1) { unique_ids.push(item.name.default); return true; } return false; }); }; var sort_by_score = function(arr) { return arr.map(function(doc) { return doc.sort(function(a,b) { return b.score - a.score; }); }).reduce(function(a,b) { //flatten return a.concat(b); }); }; module.exports = { picker: picker, dedup: dedup };