Created
July 18, 2019 17:17
-
-
Save chalu/228ca18a2228e4e122f2cee26357b56f to your computer and use it in GitHub Desktop.
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
| const sumOf = (data = [], field) => { | |
| return data.reduce((sum, entry) => { | |
| return sum += entry[field] || 0; | |
| }, 0); | |
| }; | |
| const averageOf = (data = [], field) => { | |
| return data.reduce((sum = 0, entry, index) => { | |
| const sum += (entry[field] || 0); | |
| if(index === data.length-1) return sum / data.length; | |
| return sum; | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment