utils.js 735 B

12345678910111213141516171819202122232425
  1. // 防抖函数
  2. export const debounce = (fn, wait = 1000) => {
  3. let timer;
  4. return function (...args) {
  5. clearTimeout(timer);
  6. timer = setTimeout(() => {
  7. fn.call(this, args);
  8. }, wait);
  9. };
  10. };
  11. // 深度判断两个数组是否相等(不考虑索引位置)
  12. export const areArraysEqual = (arr1, arr2) => {
  13. // 如果数组长度不同,直接返回false
  14. if (arr1.length !== arr2.length) {
  15. return false;
  16. }
  17. // 创建两个数组的副本进行排序
  18. const sortedArr1 = [...arr1].sort();
  19. const sortedArr2 = [...arr2].sort();
  20. // 逐个比较排序后的数组元素
  21. return sortedArr1.every((element, index) => element === sortedArr2[index]);
  22. };