leetcode 30 days js challenge
Easy
Given an asynchronous function fn
and a time t
in milliseconds, return a new time limited version of the input function.
A time limited function is a function that is identical to the original unless it takes longer than t
milliseconds to fullfill. In that case, it will reject with "Time Limit Exceeded"
. Note that it should reject with a string, not an Error.
Example 1:
Example 2:
Example 3:
Example 4:
Constraints:
0 <= inputs.length <= 10
0 <= t <= 1000
fn returns a promise
使用 Promise.race
方法
SheepTues, May 16, 2023