FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
Implement a custom arrayFilter function that mimics the behavior of the native filter method.
Arguments
The arrayFilter function should take an array and a callback function as arguments. The callback function should be invoked with three arguments: the current element, the index of the current element, and the array itself.
Return Value
The arrayFilter function should return a new array containing all the elements for which the callback function returns a truthy value.
Use the following example to understand how the arrayFilter function should work:
Info
Question
Implement a custom
arrayFilter
function that mimics the behavior of the nativefilter
method.Arguments
The
arrayFilter
function should take an array and a callback function as arguments. The callback function should be invoked with three arguments: the current element, the index of the current element, and the array itself.Return Value
The
arrayFilter
function should return a new array containing all the elements for which the callback function returns a truthy value.Use the following example to understand how the arrayFilter function should work:
Template
index.js
index.test.js