Last active
January 25, 2017 04:33
-
-
Save ryanjyost/ac1129bb738ee9c96caa48831302d20b to your computer and use it in GitHub Desktop.
rainy-day-fund/src/helpers.js
This file contains hidden or 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
| //src/helpers.js | |
| //take raw dollar amount (string or number) and add commas using toLocaleString | |
| export const formatDollarValues = (numString) => { | |
| if(numString == ""){ | |
| return '0'; | |
| } | |
| if(isNaN(numString)){ | |
| return '0'; | |
| } | |
| let number = Number(numString); | |
| let formattedNumber = number.toLocaleString("en"); | |
| return formattedNumber; | |
| } | |
| //take array of expense objects and caluclate total amount | |
| export const calcTotalExpenses = (expenses) => { | |
| const totalExpenses = expenses.reduce((total, expense, curr)=> { | |
| return total + expense.amount | |
| }, 0) | |
| return totalExpenses | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment