From 87971dff2cfe18ae7ba349db5f202745f5ec8eaa Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 16 Jun 2020 16:43:55 +0200 Subject: [PATCH] faster array sum --- api/networks/bounties.js | 2 +- api/utils.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/api/networks/bounties.js b/api/networks/bounties.js index 2dc186b..3f4c370 100644 --- a/api/networks/bounties.js +++ b/api/networks/bounties.js @@ -22,7 +22,7 @@ export default async function fetchBounties() { const { total, open } = await getGitcoin() log( - '✓ bounties. ' + + '✓ Bounties. ' + `Total: ${total} bounties. Open: ${open} bounties. ` + `Elapsed: ${new Date() - start}ms` ) diff --git a/api/utils.js b/api/utils.js index afed04a..854ee24 100644 --- a/api/utils.js +++ b/api/utils.js @@ -4,6 +4,13 @@ const chalk = require('chalk') const log = (text) => console.log(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 }