測(cè)試通過(guò)了
/*
?* param1 Array
?* param2 Array
?* return true or false
?*/
function arraysSimilar(arr1, arr2) {
? ? if (
? ? ? ? Object.prototype.toString.apply(arr1) === '[object Array]' &&
? ? ? ? Object.prototype.toString.apply(arr2) === '[object Array]' &&
? ? ? ? arr1.length === arr2.length
? ? ) {
? ? ? ? var arr_1 = [];
? ? ? ? var arr_2 = [];
? ? ? ? for (var i = 0; i < arr1.length; i++) {
? ? ? ? ? ? arr_1[i] = Object.prototype.toString.apply(arr1[i]);
? ? ? ? ? ? arr_2[i] = Object.prototype.toString.apply(arr2[i]);
? ? ? ? }
? ? ? ? arr_1 = arr_1.sort();
? ? ? ? arr_2 = arr_2.sort();
? ? ? ? if (JSON.stringify(arr_1) === JSON.stringify(arr_2)) {
? ? ? ? ? ? return true;
? ? ? ? } else {
? ? ? ? ? ? return false;
? ? ? ? }
? ? } else {
? ? ? ? return false;
? ? }
}
2021-12-01
沒(méi)有考慮瀏覽器的兼容,當(dāng)前運(yùn)行成功是在谷歌瀏覽器中 96.0.4664.45(正式版本) (64 位)