// 获取数字数组的最小值export const min = arr => arr.sort((x, y) => x -y)[0];// 获取数字数组的最大值export const max = arr => arr.sort((x, y) => x -y)[arr.length - 1];// 获取数字数组的总和export const sum = arr => arr.reduce((x, y) => x + y);// 获取数字数组的平均数export const avg = arr => (arr.reduce((x, y) => x + y) / arr.length).toFixed(5);// 获取数字数组的中位数export const med = arr => { const sortArr = arr.sort((x, y) => x - y); if (arr.length % 2 === 0) { return arr.slice(arr.length / 2 - 1, arr.length / 2 + 1).reduce((x, y) => x + y) / 2; } else { return sortArr[Math.floor(arr.length / 2)]; }}存到一个js文件中,在其他文件中import { min, max, sum, avg, med } from 'lib/utils';即可