日期:2014-05-16  浏览次数:20366 次

[js]js组合算法
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript"> 
            function combine(arr) {
                var r = [];
                (function f(t, a, n) {
                    if (n == 0) return r.push(t);
                    for (var i = 0; i < a[n-1].length; i++) {
                        f(t.concat(a[n-1][i]), a, n - 1);
                    }
                })([], arr, arr.length);
                return r;
            }
            var arr = [
                [1,2,3],
                ['a','b','c'],
                ['x','y','z'],
                ['e','f','g','h', 'i']];
            var res = combine(arr);
            alert(res);
        </script>
    </head>
    <body>
        <div>TODO write content</div>
    </body>
</html>

?