Implement a deepFilterArray function
Deep Filtering is not a standard term defined in JavaScript, but it is commonly well understood as the process of perform filtering operation on each depth of a nested multi-dimensional array.
1. Basic implementation
We have to implement a deepFilterArray()
utility function which takes a nested multi-dimensional array and a filter callback and returns a new array with element filtered. The depth of elements on array must be maintained.
2. Custom this binding implementation
In the above implementation, we simply invoked the filter callback, without binding the this
keyword to any value. For this implementation, we need to bind the this
value to the original input array.
Most of the implementation will remain the same, so I am highlighting only the new changes made to support the same.
3. Counting filtered elements implementation
In both the variations above, we returned the new filtered array back. However, it might be asked to simply count and return the number of items which yields a turthy value for the callback function.
The implementation for this version remains almost the same, so I will highlight only the new changes made.
Further Reading
I strongly encourage you to explore and tackle additional questions in my Recursion Questions for Frontend Interviews blog series.
By doing so, you can enhance your understanding and proficiency with recursion, preparing you to excel in your upcoming frontend interviews.
Wishing you best. Happy Interviewing 🫡.