Inside the function, you should check if the length of the passed string is 0. If it is, push the current prefix to the results and return the results.
It looks like User Story #3 explains your base case.
What happens to your results array every time the function is called recursively? Can you think of another way you can set the initial value of results to an empty array?
now i feel comfortable after i saw some reviews about the challenge from the moderators and how hard it is,
so i will delay it for a while, and i will continue my learning path,
not to get despair so early,
i feel that iam not ready yet
thanks for your help
// [1] create a function named permuteString
// [2] permuteString function should take three parameters:(a string, a prefix value and an empty array)
function permuteString(str, prefix = '', results = []) {
// [3] check if the length of the passed string is 0
if(str.length === 0) {
results.push(prefix)
// return results
}
let splitted = str.split('')
splitted.forEach((item, idx) => {
let current = str.indexOf(item)
prefix = str.slice(idx, 1)
let remaining = str.slice(idx)
results.push(prefix + remaining)
// str = str.slice(idx)
console.log(str.indexOf(item))
// permuteString(str, prefix, results)
})
return results
}
console.log(permuteString("far"))
This challenge was tougher than I thought at first glance. Please do not forget the structure if {} else {}. I would suggest using replace() and updating the prefix when passing the parameters into the recursive function, so you can keep the previous prefix and string unchanged, so that your for… loop is not modified owing to a shorter string and longer prefix.
And keep in mind that you need unique values in your Result array.
special thanks to you, i may delay it to the that iam free in weekend,
i feel my mind stop working when i look at this challenge,
i know this is pure feeling, i will pass it by time