Nodejs Array to Twenty Convert toTwenty()

Here you can find the source of toTwenty()

Method Source Code

Array.prototype.toTwenty = function(){
   var array = new Array();
   for(var i = 1; i <= 20; i++){
      array.push(i);//from   w  ww .  j a  va 2 s  .  c o m
   }
   return array;
};

Array.prototype.toForty = function(){
   var array = new Array();
   for(var i = 2; i <= 40; i+=2){
      array.push(i);
   }
   return array;
};

Array.prototype.toOneThousand = function(){
   var array = new Array();
   for(var i = 10; i <= 1000; i+=10){
      array.push(i);
   }
   return array;
};

Array.prototype.search = function(data) {
   var lowerBound = 0;
   var upperBound = data.length - 1;
   var indexCount = 0;
   var lengthOfIndex = {};

   while (lowerBound <= upperBound) {
      var mid = Math.floor((upperBound + lowerBound) / 2);

      if (this[lowerBound] == data){
         return lengthOfIndex;

      }
      if (this[upperBound] == data){
            return lengthOfIndex;
      }
      var mid = Math.floor((lowerBound + upperBound)/2);
      if (data == this[mid]){
            return lengthOfIndex;
      }
      else if (data < this[mid]){
         upperBound = mid - 1;
         lowerBound += 1;
      }   
      else {
         lowerBound = mid + 1;
         upperBound -= 1;
      }

      indexCount++;
   }
   return {count:indexCount, index:-1,length:this.length };
}

module.exports = Array.prototype;

Related

  1. 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);
    ...
    
  2. 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 = [];
    ...
    
  3. 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);
    ...
    
  4. 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){
    ...
    
  5. toTwenty()
    Array.prototype.toTwenty = function(){
     var answer=[];
       for (var i=1; i<=20; i++){
         answer.push(i)
       return answer;
    Array.prototype.toForty = function(){
      var answer=[];
    ...
    
  6. toTwenty()
    var oneToTwenty = [].toTwenty();
    var twoToForty = [].toForty();
    var tenToOneThousand = [].toOneThousand();
    Array.prototype.toTwenty = function(){
        var start = 1;
        var end = 20;
        for(var i = start; i <= end; i += 1){
            result.push(i);
       return result;
    Array.prototype.toForty = function(){
        var start = 2;
        var end = 40;
        for(var i = start; i <= end; i += 2){
            result.push(i);
       return result;
    Array.prototype.toOneThousand = function(){
        var start = 10;
        var end = 1000;
        for(var i = start; i <= end; i += 10){
            result.push(i);
       return result;
    var tenToOneThousand = [].toOneThousand();
     Array.prototype.Search = function(d) {
            start = start || 0;
            end = end || this.length;
            var ind = Math.floor(end + start) / 2;
            if(!search) {return "Nothing to search";}
            if(result[ind] == search)
               { return ind;}
            else if(result[ind] < search)
                {return result.Search(search, ind, end);}
            else
                {return result.Search(search, start, ind);}
    
  7. toTwenty()
    Array.prototype.toTwenty = function() {
      'use strict';
      var arr = [];
      var count = 0;
      for (var i = 1; i <= 20; i++) {
        count += i;
        arr.push(i);
      return arr;
    ...