zoukankan      html  css  js  c++  java
  • javascript 写了个字符串组合的情况

    function log() {
        var i = 0,
            str = '',
            args = [].slice.call(arguments);
    
        j++;
        if (isRepeat(args)) {
            k++;
            return;
        }
    
        while(i < args.length) {
            str += chars[args[i]];
            i++;
        }
        console.log(str);
    }
    
    function count(obj) {
        var i = 0;
        for (var p in obj) {
            if (obj.hasOwnProperty(p)) {
                i++;
            }
        }
        return i;
    }
    function isRepeat(arr) {
        var i = 0,
            obj = {};
        while(i < arr.length) {
            obj[typeof arr[i] + arr[i]] = 1;
            if (count(obj) === i) {
                return true;
            }
            i++;
        }
    
        return false;
    }
    function loop(min, max, fn, count) {
        var i, args;
        i = min;
        count++;
        args = [].slice.call(arguments, 0);
    
        while(i < max) {
            var iargs = args.slice(0);
            iargs.push(i);
    
            fn.apply(window, iargs.slice(4));
    
            if (count < max - min) {
                arguments.callee.apply(window, iargs);
            }
    
            i++;
        }
    }
    
    var chars = ['a', 'b', 'c', 'd', 'e', 'f'];
    
    var j = 0, k = 0;
    loop(0, chars.length, log, 0);
    console.log('共执行', j, '次, 不允许单字符重用有', j - k, '次, 允许单字符重用有', k, '次');
  • 相关阅读:
    elastic
    Leetcode题库 第十行
    Leetcode题库-实现strStr()
    Redis持久化
    Redis的数据结构及应用场景
    Redis缓存的淘汰策略
    Redis缓存常见问题
    Redis面试题1
    消息队列的原理及选型
    【转载】java高并发/mysql/mybatis/spring博客
  • 原文地址:https://www.cnblogs.com/feng524822/p/3900430.html
Copyright © 2011-2022 走看看