So I've been trying to create a function that prints out all the possible anagram for a given string ,
input:abc
output:abc,acb,bac,bca,cab,cba
But I can't complete it so the probleme is I can't insert the first letter in a specified index in a string any solution?
function anagram(str) {
if (str.length === 1) return str[0];
let collection = [];
let subStr = str.slice(1, str.length);
let subStrAnagram = anagram(subStr);
for (let i = 0; i < subStrAnagram.length; i++) {
for (let j = 0; j < subStrAnagram[i].length; j++) {
let copy = new String(subStrAnagram[i]);
}
}
return collection;
}
console.log(anagram("avc"));