You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constgetMaxAndMinArray=(a=[])=>{constl=a.length;if(l===0)return[];if(l==1){return[a[0],a[0]];}leti=0,j=l-1,max=-Infinity,min=Infinity;while(i<=j){if(a[i]<a[j]){max=max>a[j] ? max : a[j];min=min<a[i] ? min : a[i];}else{max=max>a[i] ? max : a[i];min=min<a[j] ? min : a[j];}i++;j--;}return[max,min];};
求一个给定数组中的最大数、最小数
参考答案: 请参阅 @liwenkang 清脆的回答。
另外,如果需要兼容 ES5,可以写成
Math.max.apply(0, arr)
Math.min.apply(0, arr)
本期优秀回答者: @liwenkang
The text was updated successfully, but these errors were encountered: