DEV Community

Discussion on: Immutability, Map, Filter

lukaszahradnik profile image
Lukáš Zahradník • Edited on

Your usage of async/await is wrong. First of all, you are awaiting something, that is not a promise but array, which is useless as it resolves immediately.


It seems as your intention was to await all promises in the array returned by map, which would be also wrong, because Promise.all returns promise that resolves when all passed promises resolves, no need to manually wait for them.

And your code

const result = (await Promise.all(
                       async (number) => {
                         return await isEven(number)
                    }))).filter(n=> n.isEven);

can look without all redundant stuff like this

const result = (await Promise.all(
    .filter(n => n.isEven);

and well, it's not even an async filter in the end.

pharzad profile image
Farzad Aziminia Author

Thanks for your feedback, My intention was to show my audience that the filter method is not working with an async function if you read the whole article and I was trying to show them a workaround. I'll take your feedback and update my article.