问答详情
源自:1-6 编程练习

测试通过,代码附上

function arraysSimilar(arr1, arr2) {

let t = true;

if (arr1 instanceof Array && arr2 instanceof Array ) {

if(arr1.length == arr2.length){

let a = [],

b = [];

for (let i = 0; i < arr1.length; i++) {

a.push(Object.prototype.toString.call(arr1[i]).slice(8, -1));

b.push(Object.prototype.toString.call(arr2[i]).slice(8, -1))

}

a.sort();

b.sort();

for (let j = 0; j < a.length; j++) {

if (a[j] != b[j]) {

t = false;

return false

}

}

}else t=false;

}else t=false;

return t

}


提问者:weixin_慕慕4139219 2022-03-30 12:41

个回答