Sobes.tech

Чем отличается Promise.any от Promise.race?

200

* 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 }

176

Why can't errors in the 'any' function be added via push, and why should they be assigned by index?

173

What will happen if no promises are passed to the sumPromises function?

168

What is the difference between Promise.all and Promise.allSettled?

167

What happens if you pass an empty list of functions to compose?

165

What will happen if one of the promises is rejected in the sumPromises function?

164

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.

151

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).

146

Why might the apply method be needed in the implementation of runOnce?

144

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.

141

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.

132

Do you know about the pipe pattern? How does it differ from compose?

132

Which option will be faster: using Promise.all or using a loop with await at each step? Why?

131

Why is the rejectedCount counter needed? Why can't we just look at the length of the errors array?

126