Created
November 20, 2020 20:03
-
-
Save Gerst20051/1c7bdd791b2639fa9442e8963d8bcf9e to your computer and use it in GitHub Desktop.
Should Save For User Today
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const data = require('./data.json'); | |
// jq '[ .transactions[].amount ]' data.json | |
function shouldSaveForUserToday(data) { | |
const balanceThreshold = .2; | |
const accountBalance = data.accounts[0].balance.available; | |
const transactionAmounts = data.transactions.map(transaction => transaction.amount); | |
const transactionAverage = transactionAmounts.reduce((sum, amount) => sum + amount, 0) / transactionAmounts.length; | |
return transactionAverage < 0 && Math.abs(transactionAverage) < (accountBalance * balanceThreshold); | |
} | |
console.log(shouldSaveForUserToday(data) === true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment