Nodejs Array to Twenty Convert toTwenty()

Here you can find the source of toTwenty()

Method Source Code

const binarySearch = function binarySearch (){

Array.prototype.toTwenty = function () {
 for (var i = 1; i <= 20; i++){
   this.push(i);//from www . ja  v a  2  s  . c  o m
 }
 return this;
};
Array.prototype.toForty = function () {
 for (var i = 2; i <= 40; i+=2){
   this.push(i);
 }
 return this;
};
Array.prototype.toOneThousand = function () {
 for (var i = 10; i <= 1000; i+=10){
   this.push(i);
 }
 return this;
};

Array.prototype.search = function binarySearch(randNumb) {
 var start = 0;
 var end = this.length -1;
 var answerObj = {count: 0, index: null, length: this.length};
 while(start <= end) {
   var mid = Math.floor((start + end) /2);
   if(this[end] === randNumb) {
     answerObj.index = end;
     return answerObj;
   }
   else {
      end = end - 1;
   }
  if(this[start] === randNumb) {
     answerObj.index = start;
     return answerObj;
   }
   else {
      start = start + 1;
   }
   if(this[mid] === randNumb) {
     answerObj.index = mid;
     return answerObj;
   }
   else if (this[mid] > randNumb) end = mid -1;
   else if (this[mid] < randNumb) start = mid + 1;
    answerObj.count ++;
 }
  answerObj.index = -1;
  return answerObj;
};
}

Related

  1. 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 = [];
    ...
    
  2. 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 = [];
    ...
    
  3. 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);
    ...
    
  4. 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 = [];
    ...
    
  5. 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);
    ...
    
  6. 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=[];
    ...
    
  7. toTwenty()
    Array.prototype.toTwenty = function(){
      var array = new Array();
      for(var i = 1; i <= 20; i++){
        array.push(i);
      return array;
    };
    Array.prototype.toForty = function(){
      var array = new Array();
    ...
    
  8. 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);}
    
  9. 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;
    ...