Created
July 6, 2015 20:49
-
-
Save TheIronDev/5f9870d6da4d2abd1f5d to your computer and use it in GitHub Desktop.
test getFormattedAmounts
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
+ 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