算法练习以及帅气的一行代码
### 日常用到的一行代码
##### 数组随机打乱
const shuffleArray = (arr:any[]) => arr.sort(() => Math.random() - 0.5)
##### 数组去重
const getUnique = (arr:any[]) => [...new Set(arr)]
##### 数组的最大值、最小值、平均值、和
 const max = (arr:number[])=> arr.reduce((a,b) => a>b?a:b);
    const min = (arr:number[])=> arr.reduce((a,b) => a<b?a:b);
    const average = (arr:number[]) => arr.reduce((a, b) => a + b)/arr.length;
    const sum = (arr:number[])=>arr.reduce((a,b)=> a+b);
##### 数组排序
    const ascending = (arr: number[]) => arr.sort((a, b) => a - b);    // 升序
    const decending = (arr: number[]) => arr.sort((a, b) => b - a);    // 降序
##### 页面滚动
    const scrollToTop = (element:HTMLElement) => element.scrollIntoView({ behavior: "smooth", block: "start" })   // 滚动到顶部
    const scrollToBottom = (element:HTMLElement) => element.scrollIntoView({ behavior: "smooth", block: "end" })  // 滚动到底部
##### 复制内容到粘贴板
const copyToClipboard = (text:string) => navigator.clipboard.writeText(text);
##### 生成随机颜色
const generateRandomHexColor = () => "#" + Math.random().toString(16).slice(-6);
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号