Nodejs String Reverse reverse()

Here you can find the source of reverse()

Method Source Code

// add a reverse() method to String
String.prototype.reverse = function () {
    return Array.prototype.reverse.apply(this.split('')).join('');
};

console.log('bumblebee'.reverse());

Related

  1. reverse()
    String.prototype.reverse = function() {
      var reverse = '';
      for (var i = this.length - 1; i >= 0; i--){
        reverse += this[i]
      return reverse;
    };
    
  2. reverse()
    String.prototype.reverse = function()
      var s = '';
      var i = this.length;
      while (i > 0) {
        s += this.substring(i-1,i);
        i--;
      return s;
    ...
    
  3. reverse()
    function reverseString(str) {
      var rstr = [];
      var splitStr = str.split('');
      for (i = splitStr.length -1; i >= 0; i--) {
        rstr.push(splitStr[i]);
      return rstr.join('');
    console.log(reverseString('myTest'));
    ...
    
  4. reverse()
    String.prototype.reverse = function() {
      var splitext  = this.split("");
      var revertext = splitext.reverse();
      var reversed  = revertext.join("");
      return reversed;
    };
    
  5. reverse()
    String.prototype.reverse = function() {
      return this.split("").reverse().join("");
    
  6. reverse()
    let testString = 'hello';
    let expectedString = 'olleh';
    String.prototype.reverse=function(){
      return this.split("").reverse().join("");
    console.log(testString.reverse() === expectedString);
    
  7. reverse()
    String.prototype.reverse = function() {
      var reversed = [];
      for(var i = 0; i < this.length; i++) {
        reversed[this.length - i - 1] = this[i];
      return reversed.join('');
    
  8. reverse()
    String.prototype.reverse = function () {
        var str = this.toCharArray();
        function swap(arrTemp, i, j) {
            var temp = arrTemp[i];
            arrTemp[i] = arrTemp[j];
            arrTemp[j] = temp;
        for (var i = 0, j = this.length - 1; i < j; i++, j--) {
            swap(str, i, j);
    ...
    
  9. reverse()
    String.prototype.reverse = function () {
        "use strict";
        var temp = "",
            i = 0;
        for (i; i < this.length; i = i + 1) {
            temp += this[this.length - 1 - i];
        return temp;
    };
    ...