YuriGor / deepdash

eachDeep, filterDeep, findDeep, someDeep, omitDeep, pickDeep, keysDeep etc.. Tree traversal library written in Underscore/Lodash fashion
https://deepdash.io/
MIT License
274 stars 12 forks source link

includeRoot not working on filterDeep #54

Closed GaborTorma closed 3 years ago

GaborTorma commented 4 years ago

`const tree = { id: 1,
rootKey: 'rootVal'
};

let cleaned = _.filterDeep(tree, (k, v) => k === 'rootKey' || v === 'rootVal', {includeRoot: true});

console.log(cleaned); // get empty object // expected result: { rootKey: 'rootVal' }`

YuriGor commented 4 years ago

Hi @GaborTorma! Predicate signature is similar to native js array filter or Lodash's version: value goes first, key - second let cleaned = _.filterDeep(tree, (v, k) => k === 'rootKey' || v === 'rootVal');

Also note includeRoot makes sense only if you use leavesOnly:false but in that case you should carefully decide about parent nodes, because if you return false for some parent - children will not be visited.