I'm trying to make a _.combinations
function (underscore mixin) that takes three parameters arr, pockets, duplicates
. Here's a test that I designed to show how the behavior should be.
expect(_.combinations([1, 2], 1, false)).to.be.equal([[1],[2]])
expect(_.combinations([1, 2], 1, true)).to.be.equal([[1],[2]])
expect(_.combinations([1, 2, 3], 2, false)).to.be.equal([[1,2],[1,3],[2,3]])
expect(_.combinations([1, 2, 3], 2, true)).to.be.equal([[1,2],[1,3],[2,3],[2,1],[3,1],[3,2]])
expect(_.combinations([1, 2, 3, 4], 3, false)).to.be.equal([[1,2,3],[1,2,4],[1,3,4],[2,1,4],[2,3,4],[3,4,1]])
expect(_.combinations([1, 2, 3, 4], 3, true)).to.be.equal([[1,2,3],[1,2,4],[1,3,4],[2,1,4],[2,3,1],[2,3,4],[3,1,2],[3,4,1],[3,4,2],[4,1,2],[4,1,3],[4,2,3]])
I was wondering before I go and create this function if it existed within a library already. Perhaps this specific function already has a name that I'm not familiar with.
Is there something out there that does this?