首页 > Web开发 > 详细

JS排列组合

时间:2014-07-18 16:33:30      阅读:329      评论:0      收藏:0      [点我收藏+]
<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排列组合

原文:http://www.cnblogs.com/FH-cnblogs/p/3850981.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!