permutations
Generates all permutations of an array's elements (contains duplicates).
- Use recursion.
- For each element in the given array, create all the partial permutations for the rest of its elements.
- Use
Array.prototype.map()
to combine the element with each partial permutation, thenArray.prototype.reduce()
to combine all permutations in one array. - Base cases are for
Array.prototype.length
equal to2
or1
. - ⚠️ WARNING: This function's execution time increases exponentially with each array element. Anything more than 8 to 10 entries may cause your browser to hang as it tries to solve all the different combinations.