Answers for "js reverse string method"

14

javascript string reverse

"this is a test string".split("").reverse().join("");
//"gnirts tset a si siht"

// Or
const reverse = str => [...str].reverse().join('');

// Or
const reverse = str => str.split('').reduce((rev, char)=> `${char}${rev}`, '');

// Or
const reverse = str => (str === '') ? '' : `${reverse(str.substr(1))}${str.charAt(0)}`;

// Example
reverse('hello world');     // 'dlrow olleh'
Posted by: Guest on July-02-2020
2

javascript reverse string

function reverseString(str) {
  if (str === "")
    return "";
  else
    return reverseString(str.substr(1)) + str.charAt(0);
}
reverseString("hello");
Posted by: Guest on September-03-2020
1

reverse string js

str.split('').reduce((reversed, character) =>{
    return character + reversed;
  }, '');
//apple = leppa
Posted by: Guest on July-27-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language