1.0.1 • Published 6 years ago

array-combination v1.0.1

Weekly downloads
9
License
ISC
Repository
-
Last release
6 years ago

array-combination

自由组合数组所有的可能 All the possibilities of a free combinatorial array

install

npm install --save array-combination

use

const arrayCombination = require('array-combination');

let optionList = {
  '姓名': [
    {name: '张三'},
    {name: '李四'},
  ],
  '年龄': [
    {age: '10-20'},
    {age: '20-30'},
  ],
  '其他': [
    {other: '是'},
    {other: '否'},
    {other: '1'},
  ],
};

let res = arrayCombination(optionList['姓名'], optionList['年龄'], optionList['其他']);
console.log(res);

// 输出 =>
[ [ { name: '张三' }, { age: '10-20' }, { other: '是' } ],
  [ { name: '张三' }, { age: '10-20' }, { other: '否' } ],
  [ { name: '张三' }, { age: '10-20' }, { other: '1' } ],
  [ { name: '张三' }, { age: '20-30' }, { other: '是' } ],
  [ { name: '张三' }, { age: '20-30' }, { other: '否' } ],
  [ { name: '张三' }, { age: '20-30' }, { other: '1' } ],
  [ { name: '李四' }, { age: '10-20' }, { other: '是' } ],
  [ { name: '李四' }, { age: '10-20' }, { other: '否' } ],
  [ { name: '李四' }, { age: '10-20' }, { other: '1' } ],
  [ { name: '李四' }, { age: '20-30' }, { other: '是' } ],
  [ { name: '李四' }, { age: '20-30' }, { other: '否' } ],
  [ { name: '李四' }, { age: '20-30' }, { other: '1' } ] ]