No Repeats Please - doubt before starting

Tell us what’s happening:
I have a doubt to what would be the best approach in this case…
I mean, would I need to generate each permutation and count the ones that respect the requirements, or can I go with a shortcut and use statistic calculation formulas to just get the number?

I am sure that I would get answers about doing both, and about the one that use less resources…
But what about learning and showing off abilities? What would be the best approach in that case?

Your code so far

function permAlone(str) {
  return str;


Your browser information:

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1.

Link to the challenge:

If it is purely about learning and showcasing abilities, I would suggest developing both solutions. Doing so would allow you to determine which is a more efficient, more complete solution.

For example, while the statistical computation may be more efficient time-wise, it might not take into account the limitation of repeated characters.

On the other hand, recursing with Heap’s algorithm may well give you the complete solution set, and the ability to filter it as you need, it will likely become a more intensive timed solution.

Being knowledgeable about what those differences are, I might suggest, is the kind of thing that will set you a step apart from “the herd.”

It’s kind of why I keep suggesting that folks going through the lessons should never assume that “Because I’m done that lesson, I’m done that lesson.” I am often revisiting past lessons with an eye toward “can I do this more efficiently? Or more completely?” Often the result is unexpected, but always worth the effort.

For example, I was really surprised that a for(...) loop is computationally WAY more efficient than using .map(...). And (not so surprisingly) recursion is usually more efficient than both.

I would say for the sake of completeness, the “longhand” method of gathering all permutations and filtering is the way to go. But push yourself by demonstrating the statistical route, and understand the differences. It should demonstrate to most employers a sense of curiousity and initiative.