Nodejs Array to Twenty Convert toTwenty()

Here you can find the source of toTwenty()

Method Source Code

Array.prototype.toTwenty = function(){
  for(var loop =1; loop<=20;loop++){
    this.push(loop);// w w  w.ja  v  a 2 s .  c  o m
  }
  return this;
};

Array.prototype.toForty = function(){
  for(var loop = 1;loop<=20;loop++){
    this.push(loop*2);
  }
  return this;
};

Array.prototype.toOneThousand = function(){
  for(var loop =1; loop<=100;loop++){
    this.push(loop*10);
  }
  return this;
};

Array.prototype.search = function(number){
  first = 0;
  last = this.length-1;
  var len = this.length;
  var output = {count:0, index:-1, length:len};

  while(first<=last){
    var mid = Math.floor((first+last)/2);
    if(this[first]==number){
      output.index=first;
      return output;
    }
    else if(this[last]==number){
      output.index=last;
      return output;
    }
    else if(this[mid]==number){
      output.index = mid;
      return output;
    }
    else if(this[mid]<number){
      first = mid+1;
      last -=1;
    }
    else{
    first +=1;
    last = mid -1;
      
    }
    
    output.count ++;
  }
  return output;
};

Related

  1. 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(); */
    ...
    
  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;
    Array.prototype.toForty = function(){
    ...
    
  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() {
        var arr = [];
        for (i = 0; i < 20; i++) {
            arr.push(i+1);
        return arr;
    Array.prototype.toForty = function() {
        var arr = [];
    ...
    
  7. toTwenty()
    Array.prototype.toTwenty = function(){
      var twenty = [];
      for ( var i = 1; i <= 20; i++){
        twenty.push(i)
          return twenty
    Array.prototype.toForty = function() {
      var forty = [];
    ...
    
  8. toTwenty()
    Array.prototype.toTwenty = function() {
      for(let i=1; i<=20; i++) {
        this.push(i);
      return this;
    Array.prototype.toForty = function() {
      for(let i=2; i<=40; i+=2) {
        this.push(i);
    ...
    
  9. toTwenty()
    Array.prototype.toTwenty = function() {
      var newArray = [];
      for (var i = 1; i <= 20; i++) {
        newArray.push(i);
      return newArray;
    Array.prototype.toForty = function() {
      var newArray = [];
    ...