| 12345678910111213141516171819202122232425 |
- // 防抖函数
- export const debounce = (fn, wait = 1000) => {
- let timer;
- return function (...args) {
- clearTimeout(timer);
- timer = setTimeout(() => {
- fn.call(this, args);
- }, wait);
- };
- };
- // 深度判断两个数组是否相等(不考虑索引位置)
- export const areArraysEqual = (arr1, arr2) => {
- // 如果数组长度不同,直接返回false
- if (arr1.length !== arr2.length) {
- return false;
- }
-
- // 创建两个数组的副本进行排序
- const sortedArr1 = [...arr1].sort();
- const sortedArr2 = [...arr2].sort();
-
- // 逐个比较排序后的数组元素
- return sortedArr1.every((element, index) => element === sortedArr2[index]);
- };
|