โณ
Async Filter
Async Filter์ด๋ ค์ ๋น๋๊ธฐ +40pts
Problem
Write an async filter function that filters array items with an async predicate.
Examples
Input:
await asyncFilter([1, 2, 3], async x => x > 1)Output:
[2, 3]Explanation
์ด ๋ฌธ์ ๋ **๋น๋๊ธฐ filter**๋ฅผ ๊ตฌํํ์ฌ ๋น๋๊ธฐ ์กฐ๊ฑด ํจ์๋ก ํํฐ๋งํ๋ ๋ฐฉ๋ฒ์ ํ์ตํฉ๋๋ค. ## ํต์ฌ ๊ฐ๋ : ๋น๋๊ธฐ Filter ๋น๋๊ธฐ ์กฐ๊ฑด ํจ์์ ๊ฒฐ๊ณผ๋ก ๋ฐฐ์ด์ ํํฐ๋งํฉ๋๋ค. ### ๊ตฌํ ```javascript async function asyncFilter(arr, predicate) { const results = await Promise.all(arr.map(predicate)); return arr.filter((_, i) => results[i]); } ``` ### ์ map์ ๋จผ์ ์คํํ๋๊ฐ? ...
View detailed explanation โKey Concepts
๋น๋๊ธฐ filter ์กฐ๊ฑด ํจ์ ๋ณ๋ ฌ ํ๊ฐ ์ธ๋ฑ์ค ํํฐ๋ง
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.