Created
November 10, 2017 11:04
-
-
Save loretoparisi/67354cf1cb8d9ebf57d39c7b9903606d to your computer and use it in GitHub Desktop.
Get Statistics of a Array of Objects
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
var arrayObjectStatistics = function(arr) { | |
var keys=[]; | |
arr.forEach(a => Object.keys(a).forEach(k => keys.push(a[k]))) | |
var stats=[...keys.reduce( (m, v) => m.set(v, (m.get(v) || 0) + 1), new Map() )].sort((a,b) => b[1]-a[1]) | |
stats=stats.map(c => new Object({label: c[0], count: c[1], mean: parseInt(c[1])/arr.length}) ) | |
return stats; | |
} |
Author
loretoparisi
commented
Nov 10, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment