Given
let arr = [1,2,3]; function filter(num) { return new Promise((res, rej) => { setTimeout(() => { if( num === 3 ) { res(num);
There is a one liner to to do that.
const filterPromise = (values, fn) => Promise.all(values.map(fn)).then(booleans => values.filter((_, i) => booleans[i]));
Pass the array into values and the function into fn.
values
fn
More description on how this one liner works is available here.