JS排列组合

JavaScript代码片段分析与理解
本文深入解析并执行了一个复杂的JavaScript代码片段,该代码通过函数myfind和isIn实现了特定的功能,包括数组过滤和查找。文章详细解释了代码逻辑、工作原理及应用场景,帮助读者理解和掌握JavaScript中高级操作。
<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>

 

转载于:https://www.cnblogs.com/FH-cnblogs/p/3850981.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值