各位大神,帮忙看看哪里错了,我是照着左边提醒那里打的。谢谢!
各位大神,帮忙看看哪里错了,我是照着左边提醒那里打的。谢谢!
还有求解这里是什么意思?
if(countMap1[i]){
countMap1[i]++;
}else{
countMap1[i]=1;
}
if(countMap2[i]){
countMap2[i]++;
}else{
countMap2[i]=1;
我不理解这里的if括号里面的是什么意思,还请各位大神解惑。十分感谢!!代码如下:
<!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)){
return false;
}
if(arr1.length!==arr2.length){
return false;
}
var i = 0,
n = arr1.length,
countMap1 = {},
countMap2 = {},
t1, t2,
TYPES = ['string', 'boolean', 'number', 'undefined', 'null', 'function', 'date', 'window'];
for(; i < n ; i++){
t1 = typeOf(arr1[i]);
t2 = typeOf(arr2[i]);
if(countMap1[i]){
countMap1[i]++;
}else{
countMap1[i]=1;
}
if(countMap2[i]){
countMap2[i]++;
}else{
countMap2[i]=1;
}
}
function typeOf(ele){
var r;
if(ele === null){
r = 'null';
}else if(ele instanceof Array){
r = 'array';
}else if(ele === window){
r = 'window';
}else if(ele instanceof Date){
r = 'date'
}else{
r = typeof ele;
}
return r;
}
for(i = 0 , n = TYPES.length; i < n; i++){
if(countMap1[TYPES[i]]
!== countMap2[TYPES[i]]){
return false;
}
}
return true;
}
</script>
<script src="testData.js"></script>
</body>
</html>