Nodejs String Reverse reverseString(str)

Here you can find the source of reverseString(str)

Method Source Code

/*/*from   w  w  w  .  j  a va2s.co m*/
Reverse the provided string.
You may need to turn the string into an array before you can reverse it.
Your result must be a string.
Remember to use Read-Search-Ask if you get stuck. Write your own code.

Here are some helpful links:
Global String Object
String.prototype.split()
Array.prototype.reverse()
Array.prototype.join()
*/

function reverseString(str) {
  return str.split("").reverse().join("");
}

reverseString("hello");

Related

  1. reverse() return this.split("").reverse().join(""); }
    String.prototype.reverse = function(){ return this.split("").reverse().join(""); }
    function palindrome(str) { 
       return str == str.reverse(); 
    console.log(palindrome("level"));
    
  2. reverse(str)
    String.prototype.reverse = function(str){
        return str.split("").reverse().join("");
        console.log(str)
    var myString = new String();
    myString.reverse("Happy")
    
  3. reverse(string)
    function reverse(s) {
        return s.toString().split("").reverse().join("");
        console.log('from app . js 2');
    
  4. reverseStr()
    var str = 'Lorem ipsum dolor sit amet.';
    String.prototype.reverseStr = function () {
        var string = String(this),
            tempStr = string.split('');
        tempStr = tempStr.reverse();
        return tempStr.join('');
    };
    console.log(str.reverseStr());
    
  5. reverseString()
    String.prototype.reverseString = function() {
    var len = this.length, strArray = [], ct = 0;
      for (var i=len-1;i>=0;i--) {
         strArray[ct++] = this.charAt(i);
      return strArray.join("");
    console.log("asdf ajsd".reverseString());
    
  6. reverseString.prototype.reverse || ()
    String.prototype.reverse = String.prototype.reverse || function() {
        let aux = [],   
            str = this.split('');
        while(str.length > 0) 
            aux.push(str.pop());
        return aux.join('');
    };
    
  7. reverseStringString.prototype.reverseString || reverseString( str )
    const reverseString = ( str ) => {
      return str.split(' ').reverse().join(' ');
    String.prototype.reverseString = String.prototype.reverseString || function reverseString( str ) {
      return str.split(' ').reverse().join(' ');
    module.exports = { reverseString, String };
    
  8. reverseWords()
    String.prototype.reverseWords = function() {
      var arr = this.split(" ");
      var s = "";
      while (arr.length>0) {
          var element = arr.pop();
          s += element + " ";
      return s;
    console.log("akjsdhiuao ajsd".reverseString());
    
  9. reverseWords(str)
    String.prototype.reverseWords = function(str) {
      var tokenArray = [];
      tokenArray = this.split(' ');
      return tokenArray.reverse().join(' ');