问答详情
源自:1-6 编程练习

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

<!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>


提问者:_Doogie 2020-04-13 21:33

个回答

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

    8错!?