โณ

Async Map

Async Map
๋ณดํ†ต ๋น„๋™๊ธฐ +20pts

Problem

Write an async map function that processes array items with an async callback.

Examples

Input: await asyncMap([1, 2], async x => x * 2)
Output: [2, 4]

Explanation

์ด ๋ฌธ์ œ๋Š” **๋น„๋™๊ธฐ map**์„ ๊ตฌํ˜„ํ•˜์—ฌ ๋ณ‘๋ ฌ ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ๋ฅผ ํ•™์Šตํ•ฉ๋‹ˆ๋‹ค. ## ํ•ต์‹ฌ ๊ฐœ๋…: ๋น„๋™๊ธฐ Map ๋ฐฐ์—ด์˜ ๊ฐ ์š”์†Œ์— ๋น„๋™๊ธฐ ํ•จ์ˆ˜๋ฅผ ์ ์šฉํ•˜๊ณ  ๋ชจ๋“  ๊ฒฐ๊ณผ๋ฅผ ๋ชจ์๋‹ˆ๋‹ค. ### ๊ตฌํ˜„ ```javascript async function asyncMap(arr, callback) { return Promise.all(arr.map(callback)); } ``` ### ์™œ ์ด๋ ‡๊ฒŒ ๊ฐ„๋‹จํ•œ๊ฐ€? 1. map์œผ๋กœ ๊ฐ ์š”์†Œ์— ๋น„๋™๊ธฐ ์ฝœ๋ฐฑ ์ ์šฉ โ†’ Promise ๋ฐฐ์—ด 2. Promise.all๋กœ ๋ชจ๋“  Promise ์™„๋ฃŒ ๋Œ€๊ธฐ 3. ๊ฒฐ...

View detailed explanation โ†’

Key Concepts

๋น„๋™๊ธฐ map Promise.all ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ async/await
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.