Nodejs String Reverse reverse()

Here you can find the source of reverse()

Method Source Code

String.prototype.reverse = function() {
  var sAsArray = this.split("");
  var length = sAsArray.length-1;
  var endpoint = length/2;
  var temp;/*from   w  w  w  .j ava  2s.c o  m*/

  for(var i=0; i < endpoint; i++) {
    temp = sAsArray[i];
    sAsArray[i] = sAsArray[length-i];
    sAsArray[length-i] = temp;
  }

  return sAsArray.join('');
}

Related

  1. reverse()
    function spinWords(str) {
      return str.split(' ').map(function(word) {
        return word.length > 4 ? word.reverse() : word;
      }).join(' ');
    String.prototype.reverse = function() {
      return this.split('').reverse().join('');
    };
    
  2. reverse()
    String.prototype.reverse = function() {
        var chars = this.split(''),
            new_string = '';
        for (var i = chars.length - 1; i >= 0; i--) {
            new_string += chars[i];
        return new_string;
    };
    console.log("Cat".reverse());
    ...
    
  3. reverse()
    String.prototype.reverse = function() {
        return this.split('').reverse().join('')
    
  4. reverse()
    String.prototype.reverse = function() {
      return this.split('').reverse().join('')
    'racecar'.reverse()
    'hawaii'.reverse()
    
  5. reverse()
    String.prototype.reverse = function(){
      strNew = this.split('');
      strRev = []
      for (var i = strNew.length-1; i >= 0 ; i--) {
        strRev.push(strNew[i]);
      strRev = strRev.join('');
      console.log(strRev)
    "whatup".reverse();
    
  6. reverse()
    'use strict';
    String.prototype.reverse = function (){
      return this.split("").reverse().join("");
    Number.prototype.reverse = function (){
      return this.toString().reverse();
    console.log("hello,world".reverse());
    console.log(21584.25.reverse());
    ...
    
  7. reverse()
    String.prototype.reverse = function() {
      return this.split("").reverse().join("");
    };
    
  8. reverse()
    String.prototype.reverse = function(){
       return this.split('').reverse().join('');
    var max = 0;
    for (var i = 100; i < 1000; i++) {
      for (var j = i; j < 1000; j++) {
        var product = i * j;
        if (product.toString() == product.toString().reverse() && product > max) {
          max = product;
    ...
    
  9. reverse()
    var strings = "enter the text you wish";
    String.prototype.reverse = function () {
        var len = strings.length;
        var reverseString = [];
        for (var i = 0; i < len; i++) {
            reverseString[i] = this[len - 1 - i];
        return reverseString.join("");
    console.log(strings.reverse());