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排列组合,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。