Nodejs Array to Twenty Convert toTwenty()

Here you can find the source of toTwenty()

Method Source Code

Array.prototype.toTwenty = function(){
  var twenty = [];
  for ( var i = 1; i <= 20; i++){
    twenty.push(i)//from   w ww .j  av a2  s.  com
      }
      return twenty
  }
Array.prototype.toForty = function() {
  var forty = [];
  for (var i = 2; i <= 40; i+=2){
    forty.push(i)
  }
  return forty
}
Array.prototype.toOneThousand = function(){
  var oneThousand = [];
  for (var i = 10; i <=1000; i+=10) {
  oneThousand.push (i)
  }
  return oneThousand
}
Array.prototype.search = function(num){
  var min = 0,
    index = -1,
    iterationCount = 0,
    max = this.length - 1;
  
  while (max >= min){
    var average = Math.floor((min + max) / 2);

    if (this[min] == num){
      index = min;
      break;
    }

    if (this[max] == num){
      index = max;
      break;
    }

    if (this[average] == num){
      index = average;
      break;
    }

    iterationCount += 1
    if (this[average] < num){
      min = average + 1;
    }else if (this[average] > num){
       max = average - 1;
    }
  }
  
  return {
    count: iterationCount,
    length: this.length,
    index: index
  }
}

Related

  1. toTwenty()
    Array.prototype.toTwenty = function() {
      return Array.range(20, 1);
    };
    
  2. toTwenty()
    Array.prototype.toTwenty = function(){
      a = 1;
      b = [];
      for(i=1; i<=20; i++){
        b.push(i);
      return b
    
  3. 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() {
    ...
    
  4. 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);
    ...
    
  5. 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 = [];
    ...
    
  6. 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);
    ...
    
  7. 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 = [];
    ...
    
  8. 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);
    ...
    
  9. toTwenty()
    const binarySearch = function binarySearch (){
    Array.prototype.toTwenty = function () {
     for (var i = 1; i <= 20; i++){
       this.push(i);
     return this;
    };
    Array.prototype.toForty = function () {
     for (var i = 2; i <= 40; i+=2){
    ...