-
hey, I used deepdash's filterdeep method and wrote a predicate which evaluates a boolean expression like
this doesnt work the result would be null, but if I explicit return true everything is fine (like in the official examples).
So, from the docs (https://deepdash.io/#iteratee) I figured out that this is because of "returns - return false explicitly to prevent iteration over current value's children"? Is my assumption correct and what is this called in JS? I'd like to know more about this but I fail to find anything related to this. Can someone explain or point out some words so I can check? Edit: I now think it's because it works with undefined for seen nodes so just returning true/false would not work? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi, looks like you mixing docs for eachDeep and filterDeep. eachDeep will not care about returned value unless it's exactly boolean filterDeep similar to Lodash or native array filter method expects true or false from predicate to decide keep current value or not. In case of If you are not sure yet you can read about Truthy and Falsy values in JS. Note: if in some case you function will not return something - it will mean function will still return To have better idea how deepdash works with complex nested data - I recomment first to learn how Lodash / JS array |
Beta Was this translation helpful? Give feedback.
Hi, looks like you mixing docs for eachDeep and filterDeep.
eachDeep will not care about returned value unless it's exactly boolean
false
.In this case eachDeep will skip current children if any, so it's kind of 'break' in for loop, but local for current depth level.
This is similar to convention of Lodash each method.
filterDeep similar to Lodash or native array filter method expects true or false from predicate to decide keep current value or not.
Because filterDeep case is much more complex, I extended this convention and also accept
undefined
as possible return result. If "truthy" reply will be "yes" and "falsey" response will be "no",undefined
means "Don't know yet"In case of
undef…