Nodejs Array to Twenty Convert toTwenty()

Here you can find the source of toTwenty()

Method Source Code

Array.prototype.toTwenty = function(){
    var start = 1;
    var end = 20;

    for(var i = start; i <= end; i += 1){
        this.push(i);//  w  w w . j  av  a2  s. c  o  m
    }
   return this;
}
Array.prototype.toForty = function(){
    var start = 2;
    var end = 40;

    for(var i = start; i <= end; i += 2){
        this.push(i);
    }
   return this;
}
Array.prototype.toOneThousand = function(){
    var start = 10;
    var end = 1000;

    for(var i = start; i <= end; i += 10){
        this.push(i);
    }
   return this;
}

var oneToTwenty = [].toTwenty();

console.log(oneToTwenty);


var oneToForty = [].toForty();

console.log(oneToForty); 

var oneToOneThousand = [].toOneThousand();

console.log(oneToOneThousand);

Related

  1. toTwenty()
    Array.prototype.toTwenty = function() {
      for (var i = 1; i < 21; i++) {
        this.push(i);
      return this;
    },
    
  2. toTwenty()
    Array.prototype.toTwenty = function(){
        var start = 1;
        var end = 20;
        for(var i = start; i <= end; i += 1){
            this.push(i);
       return this;
    var oneToTwenty = [].toTwenty(); */
    ...
    
  3. toTwenty()
    Array.prototype.toTwenty = function() {
      return Array.range(20, 1);
    };
    
  4. toTwenty()
    Array.prototype.toTwenty = function(){
      a = 1;
      b = [];
      for(i=1; i<=20; i++){
        b.push(i);
      return b
    
  5. toTwenty()
    'use strict';
    Array.prototype.toTwenty = function() {
      let arr = [];
      for (var i = 1; i <= 20; i++) {
        arr.push(i);
      return arr;
    Array.prototype.toForty = function() {
    ...
    
  6. toTwenty()
    Array.prototype.toTwenty = function(){
      for(var loop =1; loop<=20;loop++){
        this.push(loop);
      return this;
    };
    Array.prototype.toForty = function(){
      for(var loop = 1;loop<=20;loop++){
        this.push(loop*2);
    ...