Skip to content

Instantly share code, notes, and snippets.

@TheIronDev
Created July 6, 2015 20:49
Show Gist options
  • Save TheIronDev/5f9870d6da4d2abd1f5d to your computer and use it in GitHub Desktop.
Save TheIronDev/5f9870d6da4d2abd1f5d to your computer and use it in GitHub Desktop.
test getFormattedAmounts
+ let previousTransactions = localStorage.previousTransactions ? JSON.parse(localStorage.previousTransactions) : [],
+ amountByCount = previousTransactions.reduce(function(memo, transaction) {
+ var current = memo[transaction.value];
+ if (!current) {
+ current = {
+ value: transaction.amount,
+ currencyCode: transaction.currencyCode,
+ currencySymbol: transaction.currencySymbol,
+ count: 0
+ };
+ }
+ current.count++;
+ memo[transaction.value] = current;
+ return memo;
+ }, {}),
+ sortedAmounts = Object.keys(amountByCount)
+ .map((amount) => amountByCount[amount])
+ .sort((objA, objB) => objB.count > objA.count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment