Nodejs String Reverse reverse()

Here you can find the source of reverse()

Method Source Code

"use strict";//from  ww  w  .  j  av  a 2 s .  c  om

/**
  A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ? 99.
  Find the largest palindrome made from the product of two 3-digit numbers.
*/

String.prototype.reverse = function () {
    return this.split("").reverse().join("");
}

var isPalindrom = function(n) {
   var s = n.toString();
   return s === s.reverse();
}

var max = 0;
for (var i=100; i<1000; i++) {
   for (var j=100; j<1000; j++) {
      var k = i*j;
      if (k > max && isPalindrom(k)) {
         console.log(i + " * " + j + " = " + k);
         max = k;
      }
   }
}
// -> 913 * 993 = 906609

Related

  1. 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, ' +
    ...
    
  2. reverse()
    String.prototype.reverse=function(){
      var arr=this.toCharArray();
      return arr.reverse().join("");
    
  3. 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 () {
    ...
    
  4. reverse()
    String.prototype.reverse = function () {
        'use strict';
        var s = "",
            i = this.length;
        while (i > 0) {
            s += this.substring(i - 1, i);
            i--;
        return s;
    ...
    
  5. 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;
    };
    ...
    
  6. reverse()
    String.prototype.reverse = function() {
        var result = "";
        for (var i = this.length -1 ; i >= 0; i--){
            result += this.charAt(i);
        return result;
    };
    
  7. 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();
    ...
    
  8. reverse()
    String.prototype.reverse = function(){
      var returnedString = string.split('');
      returnedString.reverse();
      var string = this.join('');
    };
    String.prototype.reverse = function(){
      return this.split('').reverse().join('');
    var test = 'Cruncha muncha cruncha muncha fritos in my butt';
    ...
    
  9. reverse()
    String.prototype.reverse = function() {
        var s = this;
        var o = '';
        for (var i = s.length - 1; i >= 0; i--)
            o += s[i];
        return o;
    var fs  = require("fs");
    fs.readFileSync(process.argv[2]).toString().split('\n').forEach(function (line) {
    ...