Skip to content
Intern–Middle164 views

Creating your own massive filter method

Task condition

It is required to implement a custom method filter2 that works similarly to the built-in Array.prototype.filter. The method should accept a predicate function and return a new array containing only those elements for which the predicate returned a truthy value.

const numbers = [1, 2, 3, 4, 5];

const result1 = numbers.filter(item => item % 2);
console.log(result1); // [1, 3, 5]

// const result2 = numbers.filter2(item => item % 2);
Frontend tasks in the code trainer