Created
December 14, 2018 19:01
-
-
Save itacirgabral/5d42858be6c36f4e924f4ea85efb490f to your computer and use it in GitHub Desktop.
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 partitions = arr => arr.reduce((map, obj) => Object.keys(obj).reduce((map, key) =>{ | |
if (map.has(key)) { | |
map.set(key, map.get(key) + 1) | |
} else { | |
map.set(key, 1) | |
} | |
return map | |
}, map), new Map()) | |
export default partitions | |
/* | |
partitions([ | |
{"key1": "value1", "key2": "value2"}, | |
{"key1": "value1", "key3": "value3"} | |
]) | |
{"key1" => 2, "key2" => 1, "key3" => 1} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment