How to use the sum function from ramda
Find comprehensive JavaScript ramda.sum code examples handpicked from public code repositorys.
GitHub: muqsitnawaz/deepcoin
172 173 174 175 176 177 178 179 180
// For each transaction in this block, check if it is valid R.forEach(this.checkTransaction.bind(this), newBlock.transactions, referenceBlockchain); // Check if the sum of output transactions are equal the sum of input transactions + MINING_REWARD (representing the reward for the block miner) let sumOfInputsAmount = R.sum(R.flatten(R.map(R.compose(R.map(R.prop('amount')), R.prop('inputs'), R.prop('data')), newBlock.transactions))) + Config.MINING_REWARD; let sumOfOutputsAmount = R.sum(R.flatten(R.map(R.compose(R.map(R.prop('amount')), R.prop('outputs'), R.prop('data')), newBlock.transactions))); let isInputsAmountGreaterOrEqualThanOutputsAmount = R.gte(sumOfInputsAmount, sumOfOutputsAmount);
0
1
0
+ 3 other calls in file
GitHub: asan1010/apk
54 55 56 57 58 59 60 61 62 63
app: wrapped('app'), similar: wrapped('similar'), suggest: wrapped('suggest'), getInstallsScore: function (apps) { const avg = R.sum(R.pluck('minInstalls', apps)) / apps.length; const max = 1000000; const score = calc.zScore(max, avg); return {avg, score}; },
0
0
1
+ 330 other calls in file
GitHub: asan1010/apk
45 46 47 48 49 50 51 52 53 54
return {count: 0, avgRank: undefined, score: 1}; } const stats = { count: results.length, avgRank: R.sum(results) / results.length }; const countScore = calc.zScore(apps.length, stats.count); const avgRankScore = calc.iScore(1, 100, stats.avgRank);
0
0
1
+ 330 other calls in file
GitHub: asan1010/apk
66 67 68 69 70 71 72 73 74
})); } /* Build aggregate visibility score. */ const getVisbilityScore = (stats) => calc.round( R.sum(R.pluck('score', R.values(stats.keywords))) + stats.collections.global.score + stats.collections.category.score );
0
0
1
+ 270 other calls in file
2289 2290 2291 2292 2293 2294 2295 2296 2297 2298
* @param {Function} fn The function to curry. * @return {Function} A new, curried function. * @see R.curry * @example * * const sumArgs = (...args) => R.sum(args); * * const curriedAddFourNumbers = R.curryN(4, sumArgs); * const f = curriedAddFourNumbers(1, 2); * const g = f(3);
0
0
2
+ 7 other calls in file
GitHub: tanemal/not-so-naivecoin
175 176 177 178 179 180 181 182 183
// For each transaction in this block, check if it is valid R.forEach(this.checkTransaction.bind(this), newBlock.transactions, referenceBlockchain); // Check if the sum of output transactions are equal the sum of input transactions + MINING_REWARD (representing the reward for the block miner) let sumOfInputsAmount = R.sum(R.flatten(R.map(R.compose(R.map(R.prop('amount')), R.prop('inputs'), R.prop('data')), newBlock.transactions))) + Config.bitcoin.getMiningReward(this.getAllBlocks()); let sumOfOutputsAmount = R.sum(R.flatten(R.map(R.compose(R.map(R.prop('amount')), R.prop('outputs'), R.prop('data')), newBlock.transactions))); let isInputsAmountGreaterOrEqualThanOutputsAmount = R.gte(sumOfInputsAmount, sumOfOutputsAmount);
0
0
0
+ 3 other calls in file
1672 1673 1674 1675 1676 1677 1678 1679 1680 1681
* @param {Function} fn The function to curry. * @return {Function} A new, curried function. * @see R.curry * @example * * var sumArgs = (...args) => R.sum(args); * * var curriedAddFourNumbers = R.curryN(4, sumArgs); * var f = curriedAddFourNumbers(1, 2); * var g = f(3);
0
0
0
+ 35 other calls in file
GitHub: xasdx/sandbox-ramda
21 22 23 24 25 26 27 28 29
"curriesFunctions": () => { let add = (a, b) => a + b let subtract = (a, b) => a - b let sum = (...args) => R.sum(args) let f = R.curry(add)(5) expect(f(6)).to.equal(11)
0
0
0
+ 3 other calls in file
27 28 29 30 31 32 33 34 35 36 37 38
const combinationsForIndex = (index, accumMap) => { const branches = branchesMap[index] accumMap[index] = R.isEmpty(branches) ? 1 : R.sum(R.map((index) => accumMap[index], branches)) return accumMap } const combinationsMap = R.reduceRight(combinationsForIndex, [], indexRange)
0
0
0
119 120 121 122 123 124 125 126 127 128 129 130
// // [Chromosome] -> (Chromosome, [Chromosome]) const rouletteSelect = (target, population) => { const fitnesses = R.map(R.curry(fitness)(target), population) const totalFitness = R.sum(fitnesses) const cumulFitnesses = R.tail(R.scan(R.add, 0, fitnesses)) const r = Math.random() * totalFitness const [xs, ys] = R.splitWhen(
0
0
0
+ 2 other calls in file
11 12 13 14 15 16 17 18 19 20
.then(splitWhenever(equals(''))) .then(elfItems => { return mapWithIndex((items, index) => ({ ord: index + 1, items, calories: sum(items) }), elfItems); }) .then(sortByCaloriesDesc) .then(head)
0
0
0
16 17 18 19 20 21 22 23
calories: sum(items) }), elfItems); }) .then(sortByCaloriesDesc) .then(take(3)) .then(topElves => sum(map(elf => elf.calories, topElves))) .then(calories => console.log(`Top 3 elves have total of ${calories} calories`)) .catch(e => console.log('Elfs are not happy at the moment :(', e))
0
0
0
GitHub: zwc/adventofcode2016
23 24 25 26 27 28 29 30
// Finding the first dupe const findFirst = ( acc, x ) => R.ifElse( R.compose( R.contains( x ), R.tail ), R.compose( R.reduced, R.head ), R.tail)( acc ); const result = R.reduce(walk, { direction: 0, position: [ 0, 0 ], visits: [] }, input); const firstDupe = R.reduce( findFirst, result.visits, result.visits ); const distance = R.sum(R.map(Math.abs, firstDupe.split(','))); console.log(distance);
0
0
0
ramda.clone is the most popular function in ramda (30311 examples)