FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Map Async

25mins

Implement a function mapAsyncLimit(array, asyncFn, limit) that maps over an array using an asynchronous function.

The function should:

  • Accept an array of items.
  • Accept an async mapping function that returns a promise.
  • Optionally accept a limit for maximum concurrent operations. If no limit is provided, all items can be processed concurrently.
  • Return a promise that resolves to an array of mapped results in the same order as the input array.

Examples

async function toUpper(str) { return str.toUpperCase(); } await mapAsyncLimit(['a', 'b', 'c'], toUpper, 2); // ['A', 'B', 'C']

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests