《Javascript深入浅出》课程:判断两个数组是否相似
function arraysSimilar(arr1, arr2){
var objtoString = Object.prototype.toString;
if(objtoString.call(arr1)=='[object Array]' && objtoString.call(arr2)=='[object Array]'){
if(arr1.length==arr2.length){
var arr_type1 = [],
arr_type2 = [];
function m_arr_type(a1,a2){
for(var i=0;i<a1.length;i++){
var obj = objtoString.call(a1[i]);
a2[i] = (obj=='[object String]' && 1)||(obj=='[object Bloolean]' && 2)||(obj=='[object Number]' && 3)||(a1[i]+''=='undefined' && 4)||(a1[i]+''=='null' && 5)||(obj=='[object Function]' && 6)||(obj=='[object Date]' && 7)||(obj=='[object global]' && 8)||(a1[i]==window && 8)||(obj=='[object Object]' && 9);
}
return a2.sort();
}
var arr_jg1 = m_arr_type(arr1,arr_type1).toString(),
arr_jg2 = m_arr_type(arr2,arr_type2).toString();
if(arr_jg1 !== arr_jg2){
return false;
}
return true;
}else{
return false;
}
}else{
return false;
}
}