โณ

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.