JS排列组合

<script type="text/javascript">
 
function myfind(has, other, n) {
    if (n == 0) {
        document.write(has.join(","));
        document.write("<br/>");
        return;
    }
     
    if (other.length < n) {
        return;
    }
     
    var one = other.shift();
    if (isIn(has, one)) {
        myfind(has, other, n);
    } else {
        var newhas = has.concat();
        var newother = other.concat();
         
        has.push(one);
        myfind(has, other, n-1);
        myfind(newhas, newother, n);
    }
}
function isIn(has, one) {
    for (i in has) {
        if (has[i].substring(0, 3) == one.substring(0, 3)) {
            return true;
        }
    }
    return false;
}
 
var a="777 3,777 0,888 1,999 3,765 3,765 2,771 3,798 1";
myfind(new Array(), a.split(","), 6);
 
</script>

 

JS排列组合,布布扣,bubuko.com

JS排列组合

上一篇:mac 环境下 登陆失败问题Access denied for user 'root'@'localhost' (using password: YES)


下一篇:JSON 数据使用方法