Created
February 22, 2020 13:39
-
-
Save manavm1990/7a3858a2718450e8ad36b9b9180868d2 to your computer and use it in GitHub Desktop.
Given an Array of Objects, determine how many of the Objects contain a specified key
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
const countKeys = (data, key) => { | |
return data.reduce((total, datum) => (total += datum[key] ? 1 : 0), 0); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is probably not that useful outside of another example of
reduce
. After all, we might as well just use amap
to actually get the values of thatkey
☝️ ...not just count it up.