Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

objects.findLastKey #146

Closed
3 tasks done
jkvyff opened this issue Jan 2, 2020 · 1 comment
Closed
3 tasks done

objects.findLastKey #146

jkvyff opened this issue Jan 2, 2020 · 1 comment
Labels
enhancement New feature or request operator

Comments

@jkvyff
Copy link
Collaborator

jkvyff commented Jan 2, 2020

FindLastKey will return the key value of the last key whose property value it encounters that matches or returns true for the predicate

Checklist

  • implementation
  • tests
  • jsdoc

Details

A slight amalgam of version 3 and 4 of Lodash's implementation, with allowing for both array selection notation as well as a 'this' argument.

const users = {
  'barney':  { 'age': 36, 'active': true },
  'fred':    { 'age': 27, 'active': false },
  'pebbles': { 'age': 40,  'active': false }
};
 
Objects.findKey(users, function(chr) {
  return chr.age > 30;
});
// => 'pebbles' (iteration order is not guaranteed)
 
Objects.findKey(users, { 'age': 27, 'active': false });
// => 'fred'
 
Objects.findKey(users, ['active', false]);
// => 'pebbles'
 
Objects.findKey(users, 'active');
// => 'barney'

References

@evanplaice
Copy link
Member

evanplaice commented Jan 5, 2020

Added in v0.64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request operator
Projects
None yet
Development

No branches or pull requests

2 participants