Created
January 21, 2019 16:27
-
-
Save partikus/3fe338a4b7727e1937e83cf103d48f78 to your computer and use it in GitHub Desktop.
Wielka Orkiestra
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
// simple JS script to parse and sum of donations for the chosen city | |
// usage | |
// 1. copy&paste below script | |
// 2. choose the city manually | |
// 3. then call e.g. `sum().then(alert)` or sum().then(sum => { console.log(sum); }) | |
sumDonations = () => { | |
return [...document.querySelectorAll('.institution .value').values()].map(e => parseFloat(e.innerText)).reduce((a,b) => a + b, 0) | |
} | |
formatCurrency = (input, locale = 'pl-PL', currencyCode = 'PLN') => { | |
return new Intl | |
.NumberFormat(locale, { style: 'currency', currency: currencyCode }) | |
.format(input); | |
} | |
sum = () => { | |
return Promise | |
.resolve(sumDonations()) | |
.then(sum => formatCurrency(sum)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment