24.获取新数组中,在旧数组中的下标

获取新数组中,在旧数组中的下标

            var log = console.log.bind(console)
            var findCharacter = function(oldArr, newArr) {
                var that = this
                var oldArr = ['风', '刮','得','很','紧', '风']
                var newArr = ['刮', '风', '很','风', '我']
                //已经取过的数组
                var already = []

                // var commenUtilNew = commenUtil()
                // log(111, commenUtilNew)
                var result = {
                    findAll: function(a, arr) {
                        var result = []
                        var len = arr.length
                        for (var i = 0; i < len; i++) {
                            var arrIndex = arr[i]
                            if(a == arrIndex) {
                                result.push(i)
                            }
                        }
                        return result
                    },
                    returnObj: function() {
                        var self = this
                        var result = {}
                        //去重old数组
                        var newArr1 = new Set(newArr)
                        //再去循环返回
                        var len = newArr1.length
                        newArr1.forEach(function (value, index) {
                            result[value] = self.findAll(value, oldArr) || []
                        })
                        log(2222, result)
                        return result
                    },
                    // 循环取数组
                    setTime:  function() {
                        var self = this
                        var obj = self.returnObj()
                        log(1111, obj)
                        //循环返回字和index值
                        var len = newArr.length
                        for (let i = 0; i < len; i++) {
                            setTimeout(function() {
                                var a = newArr[i]

                                var arr = obj[a]

                                // var b = self.isCirculation(arr)
                                var b = arr.splice(0, 1)[0]
                                log(111111, a, b)
                            }, 500)
                        }
                    },
                }
                that.findCharacter = result
            }

            var __main = function() {
                findCharacter()


                // window.findCharacter.returnObj()
                window.findCharacter.setTime()
            }
            __main()

你可能感兴趣的:(24.获取新数组中,在旧数组中的下标)