Skip to content

Instantly share code, notes, and snippets.

@Havvy
Created January 14, 2014 23:18
Show Gist options
  • Select an option

  • Save Havvy/8427896 to your computer and use it in GitHub Desktop.

Select an option

Save Havvy/8427896 to your computer and use it in GitHub Desktop.
function keysWhere (obj, predicate) {
return Object.keys(obj).reduce(function (acc, key) {
if (predicate(key, obj[key])) {
acc.push(key);
}
return acc;
}, []);
}
keysWhere({a: 1, b: 2, c: 1}, function (key, value) { return value === 1; }); // ['a', 'c']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment