FANR
2016-04-11 12:39
function arraysSimilar(arr1, arr2){
var typeArra1=[],typeArra2=[],Similar=false;
if(arr1 instanceof Array&&arr2 instanceof Array){
for(var i=0;i<arr1.length;i++){
typeArra1[i]=getTypes(arr1[i]);
typeArra2[i]=getTypes(arr2[i]);
typeArra1.sort();
typeArra2.sort();
if(typeArra1.toString()==typeArra2.toString()){
Similar=true;
}
}
}else{
/* if(getTypes(arr1)==getTypes(arr2)){
Similar=true;
};*/
}
console.log(typeArra1.toString());
console.log(typeArra2.toString());
console.log(Similar);
return Similar;
}
function getTypes(obj){
var type=typeof obj;
if(type!="object"){
return type;
}else if(obj instanceof Date){
return "date";
}else if(obj === null){
return "null";
}else if(obj === window){
return "window";
}else {
return "object";
}
}
Null is a elementary data type.
Object is types of object.
找到哪里错了,similar在循环里面就判断为true了
JavaScript深入浅出
281100 学习 · 1020 问题
相似问题
回答 3
回答 2