Recursive string reversal function in javascript?

前端 未结 12 1619
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 08:48

I\'m a pretty experienced frontend engineer with a weak CS background. I\'m trying to get my head around the concept of recursion. Most of the examples and purported explana

12条回答
  •  不思量自难忘°
    2020-12-03 09:19

    function reverse(str) {
      if(str.charAt(0) === ''){
        return "";
      }
      return str.charAt(str.length -1) + reverse(str.substring(0,str.length-1));
    }
    

提交回复
热议问题