推荐关注
› Meteor
› JSLint - a JavaScript code quality tool
› jsFiddle
› D3.js
› WebStorm
推荐书目
› JavaScript 权威指南第 5 版
› Closure: The Definitive Guide
isbase
0.31D

JavaScript 有没有现成的穷举函数呢?

  •  
  •   isbase · Jul 4, 2016 via Android · 3726 views
    This topic created in 3775 days ago, the information mentioned may be changed or developed.
    提供需要穷举的内容之后输出所有结果
    15 replies  •  2016-07-04 23:35:13 +08:00
    just4test
    just4test
    Jul 4, 2016❤️1
    1
    没用过 js ,不过貌似 array 有 map 方法?
    没太明白你想干什么。
    isbase
    isbase
    OP
    Jul 4, 2016
    2
    @just4test
    比如 输入 26 个字母 10 个数字 输出这些字母和数字的所有组合
    learnshare
    learnshare
    Jul 4, 2016
    3
    @isbase 自己写咯
    ljbha007
    ljbha007
    Jul 4, 2016
    4
    1,2,3,4].forEach(function(i){console.log(i)})
    ljbha007
    ljbha007
    Jul 4, 2016
    5
    [1,2,3,4].forEach(function(i){console.log(i)})
    ljbha007
    ljbha007
    Jul 4, 2016❤️1
    6
    用 underscore 也可以

    _.map([1,2,3,4], function(i){console.log(i)})
    bramblex
    bramblex
    Jul 4, 2016❤️1
    7
    就一行代码的事而已,哪里那么复杂……
    var a = [1,2,3,4];
    var b = ['a','b','c','d'];
    var c = a.map((a_i) => b.map((b_i) => ([a_i, b_i]))).reduce((l, r) => r.concat(l));
    Perry
    Perry
    Jul 4, 2016
    8
    @isbase 你所说的组合是任意长度的吗?还是 36 ?
    bramblex
    bramblex
    Jul 4, 2016
    9
    javaScript 不提供 concatMap 真蛋疼……
    IanPeverell
    IanPeverell
    Jul 4, 2016❤️1
    10
    ES6 还有 Map, WeakMap, Iterator, for...of...
    lonelinsky
    lonelinsky
    Jul 4, 2016❤️1
    11
    @isbase lz 要的是全排列函数还是只是要输出 1a , 2a...1b, 2b 这样的东西?
    如果是全排列,原生 js 应该是没有这样的排列函数的,不过网上算法很多,另外提个建议,算法写出来后不要企图将结果写入一个文件(针对 26 字母+10 数字)…

    如果是后面的,随便写个 for 循环就好了吧 =。=
    Mutoo
    Mutoo
    Jul 4, 2016❤️1
    12
    楼主需要的是排列组合的库 js-combinatorics
    https://github.com/dankogai/js-combinatorics
    SourceMan
    SourceMan
    Jul 4, 2016
    13
    别人封装好的库算不算现成的?
    noe132
    noe132
    Jul 4, 2016 via Android
    14
    Array 有 reduce 方法啊
    mingyun
    mingyun
    Jul 4, 2016
    15
    @Mutoo 赞
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1302 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 22:21 · PVG 06:21 · LAX 14:21 · JFK 17:21
    ♥ Do have faith in what you're doing.