为了账号安全,请及时绑定邮箱和手机立即绑定

错误时候显示错误,那什么都不显示是啥意思???

function arraysSimilar(arr1, arr2){            
    var count = 0;            
    if (arr1.length === arr2.length) {                
        arr1.forEach(function (x) {                    
            switch(typeof x) {                        
                case "number":                        
                case "string":                        
                case "boolean":                        
                case "undefined":                        
                case "function":                            
                    var result = arr2.some(item => (typeof item) === (typeof x));                            
                    if (result === true) {                                
                        count++;                            
                    }                            
                    break;                        
                case "object":                            
                    var result = objRec(x);                            
                    result = arr2.some(item => item === result);                            
                    if (result === true) {                                
                        count++;                            
                    }                            
                    break;                    
                  }                
            });                
            if (count === arr1.length) {               
              return true;                
            }                
            else {                  
              return false;                
            }            
    }            
    return false;        
}        
function objRec(x) {            
    if (x === null) {                
        return null;            
    }            
    else if (x instanceof Date) {                
        return Date;            
    }            
    else if (x != null && x === x.window) {               
        return window;            
    }        
}


正在回答

1 回答

行吧...我自己找到问题了,貌似我代码哪里出了问题,testData.js的json读取出错。

修改了下,运行成功,显示通过。

function arraysSimilar(arr1, arr2){            
    var count = 0;            
    if (!(arr1 instanceof Array) || !(arr2 instanceof Array)) {                
        return false;            
    }            
    if (arr1.length === arr2.length) {                
        arr1.forEach(function (x) {                    
        switch(typeof x) {                        
        case "number":                        
        case "string":                        
        case "boolean":                        
        case "undefined":                        
        case "function":                            
            var result = arr2.some(item => (typeof item) === (typeof x));                            
            if (result === true) {                                
            count++;                            }                            
            break;                        
        case "object":                            
            if (x instanceof Date) {                                
                if(arr2.some(item => item instanceof Date)) {                                    
                    count++;                                
                }                            
            }                            
            else {                                
                var result = objRec(x);                                
                result = arr2.some(item => item === result);                                         
                if (result === true) {                                    
                    count++;                                
                }                            
             }                            
             break;                    
        }                
    });                
    if (count === arr1.length) {                    
        return true;                
    }                
    else {                    
        return false;                
    }            
}            
return false;        
}        
function objRec(x) {            
    if (x === null) {                
        return null;            
    }            
    else if (x instanceof Date) {                
        return Date();            
    }            
    else if (x != null && x === x.window) {                
        return window;            
    }            
    else if (x instanceof Array) {                
        return Array;            
    }            
    else {                
        return Object;            
    }        
}


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

错误时候显示错误,那什么都不显示是啥意思???

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信