Last active
November 3, 2016 23:23
-
-
Save robvolk/a7e4a0804e7f945d4c7c3a2e8c32ff01 to your computer and use it in GitHub Desktop.
Determine if a hash has any of a set of values defined using sweet ES6 functional programming methods #map and #reduce
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
function hasValues(hash, fields) { | |
return fields.map(field => { | |
return hash[field] != null; | |
}).reduce((x, y) => { return x || y }); | |
} | |
hash = { name: "robert paulson", affiliation: "fightclub" }; | |
hasValues(hash, [ "name", "email" ]); // => true | |
hasValues(hash, [ "email" ]); // => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment