校验数组是否为空
const isNotEmpty = arr => Array.isArray(arr) && !!arr.length; isNotEmpty([1, 2, 3]); // Result: true
回到顶部
function topFunction() { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; }
求数字的平均值
const average = (...args) => args.reduce((a, b) => a + b) / args.length; average(1, 2, 3, 4); // Result: 2.5
校验数字是奇数还是偶数
const isEven = num => num % 2 === 0; console.log(isEven(2)); // Result: True
数组去重
const removeDuplicates = (arr) => [...new Set(arr)]; console.log(removeDuplicates([1, 2, 3, 3, 4, 4, 5, 5, 6])); // Result: [ 1, 2, 3, 4, 5, 6 ]
标签:arr,const,为空,args,校验,Result,数组 From: https://www.cnblogs.com/zihang-cheng/p/16794659.html