1、前端如何实现请求并发控制20个请求需要发送,由于某些原因,需要我们将同一时刻的并发请求数量控制在3个以内,并且需要尽快拿到响应结果/** * 前端如何实现请求并发控制 * * 实现一个并发请求函数concurrencyRequest(urls, maxNum),要求如下: * • 要求最大并发数 maxNum * • 每当有一个请求返回,就留下一个空位,可以增加新的请求 * • 所有请求完成后,结果按照 urls 里面的顺序依次打出(发送请求的函数可以直接使用fetch即可) */ const concurrencyRequest = (urls: string[], maxNum: number) => { return new Promise((resolve) => { const results: Response[] = [], _maxReqNum = urls.length; let _records = maxNum; const request = (idx) => { con
1、确定单调栈的递增/递减方向2、每次移动保证当前值与栈顶数据的实时更新递增方向: 当遍历元素小于或等于栈顶元素时,入栈,调整栈顶元素为最新移入的最小值,依次遍历,当获取大值时,出栈顶,计算差值,直到栈顶元素大于遍历当前元素最新值,最新值入栈,重复此过程,直到遍历完成 function dailyTemperatures(temperatures: number[]): number[] { const result = new Array(temperatures.length).fill(0), st = [0]; for(let i = 1; i < temperatures.length; i++) { if(temperatures[i] <= temperatures[st[st.length - 1]]) { st.push(i); } else { while(st.length >0 && temperatures[i] > t
李优秀同学
待会去码头整点薯条