1
0
mirror of https://github.com/oceanprotocol/community-numbers.git synced 2024-12-22 17:23:31 +01:00

faster array sum

This commit is contained in:
Matthias Kretschmann 2020-06-16 16:43:55 +02:00
parent 61a4fc5072
commit 87971dff2c
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 9 additions and 2 deletions

View File

@ -22,7 +22,7 @@ export default async function fetchBounties() {
const { total, open } = await getGitcoin() const { total, open } = await getGitcoin()
log( log(
'✓ bounties. ' + '✓ Bounties. ' +
`Total: ${total} bounties. Open: ${open} bounties. ` + `Total: ${total} bounties. Open: ${open} bounties. ` +
`Elapsed: ${new Date() - start}ms` `Elapsed: ${new Date() - start}ms`
) )

View File

@ -4,6 +4,13 @@ const chalk = require('chalk')
const log = (text) => console.log(text) const log = (text) => console.log(text)
const logError = (text) => console.error(chalk.bold.red(text)) const logError = (text) => console.error(chalk.bold.red(text))
const arrSum = (arr) => arr.reduce((a, b) => a + b, 0) const arrSum = (arr) => {
var sum = 0
arr.forEach(function (v) {
if (typeof v === 'object') sum += arrSum(v)
else sum += v
})
return sum
}
module.exports = { log, logError, arrSum } module.exports = { log, logError, arrSum }