Is there any pre-built method for finding all permutations of a given string in JavaScript?

前端 未结 8 2134
遥遥无期
遥遥无期 2020-11-28 10:28

I\'m a newbie to the JavaScript world. As the title mentions, I want to know whether there is any pre-built method in JavaScript to find all possible permutations of a give

8条回答
  •  無奈伤痛
    2020-11-28 10:54

    function permutations(str){
      if (str.length === 1)
          return str;
      var permut = [];
      for (var i=0; i

    permutations('the');
    //output returns:[ 'the', 'teh', 'het', 'hte', 'eth', 'eht' ]

提交回复
热议问题