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

Filter function #16

Open
emahuni opened this issue Aug 16, 2018 · 0 comments
Open

Filter function #16

emahuni opened this issue Aug 16, 2018 · 0 comments

Comments

@emahuni
Copy link

emahuni commented Aug 16, 2018

Ok so the get function is there, but it gets the end obj/arr. A filter function will be great that does this:

const members = [
  { username: 'gumbouser', profile: { age: 33 } },
  { username: 'tsuyoshiwada', profile: { age: 24 } },
  { username: 'sampleuser', profile: { age: 30 } },
  { username: 'foobarbaz', profile: { age: 33 } }
];
 
dot.filter(members, '*.age', 33);
// => [  { username: 'gumbouser', profile: { age: 33 } },
//         { username: 'foobarbaz', profile: { age: 33 } }  ]

returns the objects that have hits from the root.

Implementation is simple here (sketch):

Filter function. takes in obj (object to filter) and path (the dot-wild path to use)

  // filter function
 return  obj.filter(o => dot.has(o, path)); 

the path given can/should take into account that this is an inner part of the obj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant