Nodejs Array to Twenty Convert toTwenty()

Here you can find the source of toTwenty()

Method Source Code

/**/*  ww  w .  j  a v a  2  s. co  m*/
 * Created by Maranatha Ilesanmi on 3/15/2017.
 */


Array.prototype.toTwenty = function() {
    var arr = [];
    for (i = 0; i < 20; i++) {
        arr.push(i+1);
    }
    return arr;
}

Array.prototype.toForty = function() {
    var arr = [];
    for (i = 0; i < 40; i+=2) {
        arr.push(i+2);
    }
    return arr;
}

Array.prototype.toOneThousand = function() {
    var arr = [];
    for (i = 0; i < 1000; i+=10) {
        arr.push(i+10);
    }
    return arr;
}

Array.prototype.search = function(n) {
    var index1 = 0;
    var index2 = this.length - 1;
    var curIndex;
    var curElement;
    var count = 0;

    while (index1 <= index2) {
        curIndex = (index1 + index2) / 2 | 0;
        curElement = this[curIndex];

        if (curElement < n) {
            index1 = curIndex + 1;
        } else if (curElement > n) {
            index2 = curIndex - 1;
        } else {
            break;
        }
        curIndex = -1;

    }

    return {"count":count, "index": curIndex, "length":this.length};
}

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