Created
January 16, 2015 20:52
-
-
Save justinobney/85ab58b8bef334384671 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
function pick(collection, properties){ | |
[].map.call(collection, function(val, key){ | |
var result = {}; | |
properties.forEach(copyProperty); | |
return result; | |
function copyProperty(propName){ result[propName] = val[propName]; } | |
}) | |
} | |
pick([{name:'justin', id:1}], ['name']); | |
// produces => [{name:'justin'}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment