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

没毛病吧这个代码


<!DOCTYPE HTML>

<html>

<head>

    <meta charset="utf-8">

    <title>Untitled Document</title>

    

</head>

<body>

    <script type="text/javascript">   

        /*

         * param1 Array 

         * param2 Array

         * return true or false

         */

        function arraysSimilar(arr1, arr2){

            if(arr1.length!==arr2.length){

                return false;

            }

            var str=0,bool=0,num=0,func=0,date=0,win=0,undef=0,nul=0;

            for(const i of arr1){

                switch(typeof i){

                    case 'string':

                        str++;

                        break;

                    case 'boolean':

                        bool++;

                        break;

                    case 'number':

                        num++;

                        break;

                    case 'function':

                        func++;

                        break;

                    case 'date':

                        date++;

                        break;

                    case 'window':

                        win++;

                        break;

                    case 'undefine':

                        undef++;

                        break;

                    case 'null':

                        nul++;

                        break;

                }

            }

            for(const i of arr2){

                switch(typeof i){

                    case 'string':

                        str--;

                        break;

                    case 'boolean':

                        bool--;

                        break;

                    case 'number':

                        num--;

                        break;

                    case 'function':

                        func--;

                        break;

                    case 'date':

                        date--;

                        break;

                    case 'window':

                        win--;

                        break;

                    case 'undefine':

                        undef--;

                        break;

                    case 'null':

                        nul--;

                        break;

                }

            }

            if(str||bool||num||func||date||win||undef||nul){

                return false;

            }

            return true;

        }

        function f1(){


        }

        function f2(){


        }

        let arr1=[1,f2],arr2=[1,f1];

        if(arraysSimilar(arr1,arr2)){

            alert("判定结果:通过");

        }

        else{

            alert("判定结果:不通过");

        }

    </script>

    <script src="testData.js"></script>

</body>

</html>


正在回答

2 回答

哇,为啥你要写这么复杂

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

typeof对于window,undefine,null是无法区分的(都会判断为对象类型object),需要使用instanceof来进一步判断是哪种对象类型。

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

举报

0/150
提交
取消

没毛病吧这个代码

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