diff --git a/index.js b/index.js index 0e616bf..eacb354 100644 --- a/index.js +++ b/index.js @@ -15,10 +15,9 @@ var combo = function(a, min, max) { return; } var all = []; - for (var i = min; i < a.length; i++) { + for (var i = min; i <= max; i++) { fn(i, a, [], all); } - if(a.length == max) all.push(a); return all; } module.exports = combo; diff --git a/test/combo.test.js b/test/combo.test.js index 95d4771..19d5280 100644 --- a/test/combo.test.js +++ b/test/combo.test.js @@ -32,5 +32,11 @@ suite('combo', function() { assert.deepEqual(out, [ [ 'a', 'b' ], [ 'a', 'c' ], [ 'a', 'd'], [ 'b', 'c' ], [ 'b', 'd'], [ 'c', 'd' ], [ 'a', 'b', 'c' ], [ 'a', 'b', 'd' ], [ 'a', 'c', 'd' ], [ 'b', 'c', 'd' ] ]); }); + test('4 item array with min 3 and max 3 elements', function() { + var out = combo(['a', 'b', 'c', 'd'],3,3); + + assert.deepEqual(out, [ [ 'a', 'b', 'c' ], [ 'a', 'b', 'd' ], [ 'a', 'c', 'd' ], [ 'b', 'c', 'd' ] ]); + }); + });