Nodejs String Reverse reverse()

Here you can find the source of reverse()

Method Source Code

/*jslint node: true, plusplus: true, unparam: false, nomen: true*/
String.prototype.reverse = function () {
    'use strict';
    var s = "",
        i = this.length;/*  w  w w. ja v a  2 s.co  m*/
    while (i > 0) {
        s += this.substring(i - 1, i);
        i--;
    }
    return s;
};

function createDateString() {
    'use strict';
    var dateObject = new Date(),
        hours = ('0' + dateObject.getHours()).reverse().substring(0, 2).reverse(),
        minutes = ('0' + dateObject.getMinutes()).reverse().substring(0, 2).reverse();
    return "[" + hours + ":" + minutes + "] ";
}

module.exports = createDateString;

Related

  1. reverse()
    String.prototype.reverse = function ()
        var value = '';
        for(var i = this.length - 1; i >= 0; i--)
            value += this.charAt(i);
        return value;
    };
    ...
    
  2. reverse()
    function reverseSlow(s) {
      let result = '';
      for (let i = s.length - 1; i >= 0; i--) {
        result += s.charAt(i);
      return result;
    function reverseFast(s) {
      let result = [];
    ...
    
  3. reverse()
    String.prototype.reverse = function () {
        return this.split('').reverse().join('');
    };
    String.prototype.isPalindrome = function () {
        var s = this.toLowerCase().replace(/[^a-z]/g, '');
        return (s.reverse() === s);
    };
    ('A man, a plan, a canoe, pasta, heros, rajahs, ' +
    'a coloratura, maps, snipe, percale, macaroni, ' +
    ...
    
  4. reverse()
    String.prototype.reverse=function(){
      var arr=this.toCharArray();
      return arr.reverse().join("");
    
  5. reverse()
    function reverseWordsInString(str) {
        var words = str.split(' ');
        var resultStr = '';
        for (var w in words) {
            resultStr += words[w].reverse() + ' ';
        return resultStr;
    String.prototype.reverse = function () {
    ...
    
  6. reverse()
    String.prototype.reverse = function(){
      var charArray = this.split('');
      var charArrayLength = charArray.length;
      var reverseMessage = '';
      for(var i = charArrayLength-1;i>=0;i--){
        reverseMessage+=charArray[i];
      return reverseMessage;
    };
    ...
    
  7. reverse()
    "use strict";
    String.prototype.reverse = function () {
        return this.split("").reverse().join("");
    var isPalindrom = function(n) {
      var s = n.toString();
      return s === s.reverse();
    var max = 0;
    ...
    
  8. reverse()
    String.prototype.reverse = function() {
        var result = "";
        for (var i = this.length -1 ; i >= 0; i--){
            result += this.charAt(i);
        return result;
    };
    
  9. reverse()
    String.prototype.reverse = function(){
      var newString = "";
      for (var i = this.length - 1; i >= 0; i--) {
        newString = newString + this[i];
      };
      return newString;
    var name = "freak yeah I\'m writing strings up in hurr!!"
    name.reverse();
    ...