虽然做出来了,但感觉还是粗糙

来源:1-6 编程练习

_Doogie

2020-04-13 21:33

<!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 hdlarr1 = getType(arr1).sort();
                    var hdlarr2 = getType(arr2).sort();
                    for(var i=0;i<hdlarr1.length;i++){
                        console.log(hdlarr1[i],hdlarr2[i]);
                        if(hdlarr1[i] !== hdlarr2[i]){
                            return false;
                        }
                    }
                }else{
                    return false;
                }
                return true;
            }else{
                return false;
            }
        }
        
        //返回数组类型
        function getType(arr){
            var result = [];
            for(var i=0;i<arr.length;i++){
                var tag = Object.prototype.toString.apply(arr[i]);
                result.push(tag.slice(8,-1));
            }
            return result;
        }
    </script>
    <script src="testData.js"></script>
</body>
</html>


写回答 关注

1回答

  • qq_慕慕947699
    2020-04-14 11:24:25

    8错!?

JavaScript深入浅出

由浅入深学习JS语言特性,且解析JS常见误区,从入门到掌握

281101 学习 · 1020 问题

查看课程

相似问题