Waiting for the first successful promise
JavaScript
Easy
promises
Task «Waiting for the first successful promise»
Write a function `firstResolved(promises)` that takes an array of promises and returns a new promise that resolves with the value of the first successfully resolved promise from the array. If all promises are rejected, the returned promise should be rejected with the message "All promises rejected". Use only standard promise methods, without async/await.
Input Format
A string with an array of promises in JSON format, where each promise is represented as [resolve, value] or [reject, error]. For example: [[true, 10], [false, 'Error'], [true, 20]].
Output Format
The value of the first successfully resolved promise or the string 'All promises rejected'.
Examples
Example 1
INPUT
[[true, 10], [true, 20], [false, 'Error']]
OUTPUT
10
Example 2
INPUT
[[false, 'Error1'], [true, 'Success'], [false, 'Error2']]
OUTPUT
Success
Example 3
INPUT
[[false, 'Error1'], [false, 'Error2']]
OUTPUT
All promises rejected
main.js