Skip to main content

Async Filter

MIDDLE

Async Filter

Implement an async version of Array.filter that filters items with an async predicate.

Requirements:

  • Implement asyncFilter that takes an array and async predicate function
  • Test each item with the predicate
  • Return only items where predicate returns true
  • Maintain original order

Example:

const numbers = [1, 2, 3, 4, 5];
const isEven = async (n) => n % 2 === 0;

asyncFilter(numbers, isEven).then(result => {
  console.log(result); // [2, 4]
});

Examples:

Input 1:{"array":[1,2,3,4,5]}
Output 1:[2,4]
Input 2:{"array":[1,2,3,4]}
Output 2:[3,4]

Loading editor...

Run your code to see results

Click the Run button above