虽然通过了,但是感觉写得很头铁,有什么优化的建议吗?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb18030">
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
/*
* param1 Array
* param2 Array
* return true or false
*/
function arraysSimilar(arr1, arr2){
if(arr1 instanceof Array && arr2 instanceof Array){
if(arr1.length == arr2.length){
var arr1t=[];
var arr2t=[];
var len=arr1.length
for(i=0;i<len;i++){
arr1t.push(Object.prototype.toString.apply(arr1[i]));
arr2t.push(Object.prototype.toString.apply(arr2[i]));
}
arr1t.sort();
arr2t.sort();
//document.write(arr1t+"<br>");
//document.write(arr2t+"<br>");
if(arr1t.toString()==arr2t.toString()){
return true
}
else{return false}//
}
else{return false}//长度对比失败
}
else{return false} //数组对比失败
}
</script>
<script src="testData.js"></script>
</body>
</html>