小编kmu*_*nky的帖子

组合用例的数组

Node.js应用程序,编写验证测试.鉴于以下内容:

var obj = { foo: null, bar: null, baz: null},
    values = [ 0, 1];
Run Code Online (Sandbox Code Playgroud)

我需要创建n个对象来解释为每个可能值的组合分配的每个属性,以表示每个可能的用例.因此,对于此示例,输出应为2 ^ 3 = 8个对象,例如

[
    { foo: 0, bar: 0, baz: 0},
    { foo: 0, bar: 1, baz: 0},
    { foo: 0, bar: 1, baz: 1},
    { foo: 0, bar: 0, baz: 1},
    { foo: 1, bar: 0, baz: 0},
    { foo: 1, bar: 1, baz: 0},
    { foo: 1, bar: 1, baz: 1},
    { foo: 1, bar: 0, …
Run Code Online (Sandbox Code Playgroud)

javascript arrays testing node.js

2
推荐指数
1
解决办法
284
查看次数

标签 统计

arrays ×1

javascript ×1

node.js ×1

testing ×1