码迷,mamicode.com
首页 > Web开发 > 详细

JS排列组合

时间:2014-07-18 16:33:51      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:style   blog   java   color   io   for   

<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排列组合

标签:style   blog   java   color   io   for   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!