How to use the reduce function from underscore
Find comprehensive JavaScript underscore.reduce code examples handpicked from public code repositorys.
367 368 369 370 371 372 373 374 375 376
//ar = _.shuffle(ar) ar = _.sortBy(ar, (r) => {return - Number(r.probability || 0) }) var total = _.reduce(ar, function(sum, r){ return sum + Number(r.probability || 0) }, 0) if (total <= 0) return ar[f.rand(0, ar.length - 1)]
33
58
7
+ 2 other calls in file
GitHub: Ashteki/ashteki
318 319 320 321 322 323 324 325 326 327
const foundDie = allDice.find((die) => die.uuid === dieId); return foundDie; } getAllDice() { const dieUpgrades = _.reduce( this.cardsInPlay, (dice, card) => { return dice.concat(card.dieUpgrades); },
9
10
1
+ 3 other calls in file
GitHub: Cloud-V/Backend
377 378 379 380 381 382 383 384 385 386
query.deleted = false; query.authComplete = true; query.type = UserType.Regular; return new Promise(async (resolve, reject) => { const userPaths = _.pickSchema(userModel); const projection = _.reduce( userPaths, (accum, val) => { if (!/\./.test(val)) { accum[val] = 1;
0
2
0
GitHub: ArVinD-005/RepoA
794 795 796 797 798 799 800 801 802 803
return _.filter(array, function(value){ return !!value; }); }; // Return a completely flattened version of an array. _.flatten = function(array, shallow) { return _.reduce(array, function(memo, value) { if (_.isArray(value)) return memo.concat(shallow ? value : _.flatten(value)); memo[memo.length] = value; return memo; }, []);
0
0
1
+ 20 other calls in file
101 102 103 104 105 106 107 108 109 110
} else { paths = path.split(/[\.\[]/); nPath = _.first(paths); } remainingPath = _.reduce(_.rest(paths), function(result, item) { if (!_.isEmpty(item)) { if (item.match(/^\d\]/)) { item = "[" + item; }
0
0
1
+ 5 other calls in file
underscore.keys is the most popular function in underscore (11266 examples)