Nodejs String Reverse reverser()

Here you can find the source of reverser()

Method Source Code

// As a string extension
// note: doesn't work with arrow syntax from ES6
String.prototype.reverser = function() {
  if (!this || this.length < 2) {
    return this;//from  w w  w. ja  v  a 2  s.com
  }
    return this.split('').reverse().join('');
}

Related

  1. reverseString(str)
    function reverseString(str) {
      return str.split("").reverse().join("");
    reverseString("hello");
    
  2. 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('');
    };
    
  3. 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 };
    
  4. 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());
    
  5. reverseWords(str)
    String.prototype.reverseWords = function(str) {
      var tokenArray = [];
      tokenArray = this.split(' ');
      return tokenArray.reverse().join(' ');
    
  6. strReverse()
    String.prototype.strReverse = function() {
      var length = this.length,
          strcopy = '';
      for(var i = length-1; i >= 0; i--) {
        strcopy+=this[i]
      return strcopy;
    console.log("  0011".strReverse())
    ...