Skip to content

Instantly share code, notes, and snippets.

@ryanjyost
Last active January 25, 2017 04:33
Show Gist options
  • Select an option

  • Save ryanjyost/ac1129bb738ee9c96caa48831302d20b to your computer and use it in GitHub Desktop.

Select an option

Save ryanjyost/ac1129bb738ee9c96caa48831302d20b to your computer and use it in GitHub Desktop.
rainy-day-fund/src/helpers.js
//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