I am trying to call the filterArr method inside the filterArr itself. Here is my current implementation:
function filterArr(array, search) {
var result = [];
array.forEach((a)=> {
var temp = [],
o = {},
found = false;
if (a.name === search) {
o.name = a.name;
found = true;
}
if (Array.isArray(a.children)) {
temp = filterArr(a.children, search); //***Cannot read property 'filterArr' of undefined***
if (temp.length) {
o.children = temp;
found = true;
}
}
if (found) {
result.push(o);
}
});
return result;
}
What is the solution to call the filterArr method without encountering any errors?