ES6 ...rest In Action
ES6 ...rest In Action
const arr = [
2.48, 13.77, 8.64,
20.17, 8.94, 8.07,
12.05, 5.71, 17.54,
2.63
];
// (10) [2.48, 13.77, 8.64, 20.17, 8.94, 8.07, 12.05, 5.71, 17.54, 2.63]
const [min, ...rest1] = arr.sort((a, b) => a - b > 0 ? 1 : -1);
// (10) [2.48, 2.63, 5.71, 8.07, 8.64, 8.94, 12.05, 13.77, 17.54, 20.17]
min;
// 2.48
const [max, ...rest2] = arr.sort((a, b) => a - b > 0 ? -1 : 1);
// (10) [20.17, 17.54, 13.77, 12.05, 8.94, 8.64, 8.07, 5.71, 2.63, 2.48]
max;
// 20.17
refs
最简单的方法实现微信红包的随机算法
https://www.cnblogs.com/xgqfrms/p/13688375.html
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13689512.html
未经授权禁止转载,违者必究!