Problem 49
String Permutations Recursion Challenge
Given a string, return an array containing every unique permutation of its characters. The order of the returned permutations does not matter. If the string contains duplicate characters, do not include duplicate permutations.
Function Signature
permutations(str)
Parameters
str— a string of characters, which may include repeated letters.
Output
Return an array of strings, each being a unique permutation of the input.
Constraints
- The function must use recursion.
- Duplicate permutations should not be included.
- The function should accept exactly one argument.
Examples
permutations('') → ['']
permutations('a') → ['a']
permutations('ab') → ['ab', 'ba']
permutations('abc') → ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
permutations('aa') → ['aa']
permutations('aba') → ['aab', 'aba', 'baa']