DEV Community

Discussion on: Filtering an array using a function that returns a promise

praveenkumarrr profile image
Praveen Author • Edited on

Hi @devscover ,

setTimeout doesnot return a promise. The solution provided in this article is for promises. So you have to convert the setTimeout to promise. Once I change the below function, I get the correct result.

async function asyncFilterOldEnough(person) {
    return new Promise(res => setTimeout(function () {
        res(person.age > 26);
    }, 3000));
Enter fullscreen mode Exit fullscreen mode