慕田峪2351594
2020-05-26 09:54
function arraysSimilar(arr1, arr2){ if(arr1.length != arr2.length) return false; function processData(arr){ var _arr = []; for(var i = 0; i < arr.length; i++){ _arr.push(Object.prototype.toString.call(arr[i])); } return _arr.sort().join(','); } return processData(arr1) === processData(arr2); }
?没有格式化
function arraysSimilar(arr1, arr2){ if(arr1.length != arr2.length) return false; let arr1type = typeStrArr(arr1); let arr2type = typeStrArr(arr2); let status = true; arr1type.forEach(item => { let isHas = arr2type.find(el => item == el); if(!isHas){ status = !!isHas; return; } }) return status; function typeStrArr(array){ let arr = []; array.forEach(item => { let t = Object.prototype.toString.call(item).slice(8, -1); arr.push(t) }) return arr; } }
哥们你没有考虑顺序问题
JavaScript深入浅出
281101 学习 · 1020 问题
相似问题