Чем отличается Promise.any от Promise.race?
Frontend
* The function takes an array of promises (assumed non-empty) and returns a promise. * If any of the passed promises resolve (successfully complete), then the returned promise resolves with that value. * If multiple promises are successfully fulfilled, then the returned promise resolves * with the first successful value, regardless of the order of promises in the array. * If all passed promises reject, then the returned promise rejects with an AggregateError, which groups all errors, considering the order of promises. * An AggregateError can be created as follows: new AggregateError(errors, 'No Promise in any was resolved') function any(promises) { // your code here }
Why can't errors in the 'any' function be added via push, and why should they be assigned by index?
What will happen if no promises are passed to the sumPromises function?
What is the difference between Promise.all and Promise.allSettled?
What happens if you pass an empty list of functions to compose?
What will happen if one of the promises is rejected in the sumPromises function?
Implement a function sumPromises that takes promises as arguments and returns the sum of their resolved results. The function can accept any number of arguments. You may use any Promise APIs.
Implement a function isMonotonic that takes an array of numbers and determines if it is monotonic (non-increasing or non-decreasing). Return true if it is monotonic, otherwise false. Implement with linear complexity O(n).
Why might the apply method be needed in the implementation of runOnce?
Implement a function compose that takes a variable number of functions and returns a new function. The result of each function is passed to the next.
Implement a runOnce wrapper function that takes a function and returns a new function. The new function can only be called once, all subsequent calls return undefined. The wrapped function can take arguments and return a result.
Do you know about the pipe pattern? How does it differ from compose?
Which option will be faster: using Promise.all or using a loop with await at each step? Why?
Why is the rejectedCount counter needed? Why can't we just look at the length of the errors array?