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:
parent
61a4fc5072
commit
87971dff2c
@ -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`
|
||||||
)
|
)
|
||||||
|
@ -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 }
|
||||||
|
Loading…
Reference in New Issue
Block a user