There is a highly organized city that has decided to assign a number to each of their departments:
Police department Sanitation department Fire departmentEach department can have a number between 1 and 7 (inclusive).
The three department numbers are to be unique (different from each other) and must add up to the number 12.
The Chief of the Police doesn't like odd numbers and wants to have an even number for his department.
Task:Write a program which outputs all valid combinations:
[2, 3, 7]
[2, 4, 6]
[2, 6, 4]
[2, 7, 3]
[4, 1, 7]
[4, 2, 6]
[4, 3, 5]
[4, 5, 3]
[4, 6, 2]
[4, 7, 1]
[6, 1, 5]
[6, 2, 4]
[6, 4, 2]
[6, 5, 1]
combinations
should be a function.
testString: assert(typeof combinations === 'function', 'combinations
should be a function.');
- text: combinations([1, 2, 3], 6)
should return an Array.
testString: assert(Array.isArray(combinations([1, 2, 3], 6)), 'combinations([1, 2, 3], 6)
should return an Array.');
- text: combinations([1, 2, 3, 4, 5, 6, 7], 12)
should return an array of length 14.
testString: assert(combinations(nums, total).length === len, 'combinations([1, 2, 3, 4, 5, 6, 7], 12)
should return an array of length 14.');
- text: combinations([1, 2, 3, 4, 5, 6, 7], 12)
should return all valid combinations.
testString: assert.deepEqual(combinations(nums, total), result, 'combinations([1, 2, 3, 4, 5, 6, 7], 12)
should return all valid combinations.');
```