Nodejs Array Range range(first, second)

Here you can find the source of range(first, second)

Method Source Code

Array.prototype.range = function(first, second) {
  var range = []//from w ww .  j a  v a 2  s  .c  o  m

  console.log(typeof second)

  // only one argument means an array from
  // 0
  if (typeof second === 'undefined') {
    for (var i = 0; i < first; i++) {
      range.push(i)
    }
    return range
  }

  // two arguments means an array from
  // 'first' to 'second'
  for (var i = first; i < second; i++) {
    range.push(i)
  }

  return range
}

Related

  1. range()
    Array.prototype.range = function(){
      var a = this.natsort();
      return this[a.length-1]-a[0];
    };
    
  2. range()
    Array.prototype.range = function() {
        function isArray(instance) {
            return Object.prototype.toString.call(instance) !== '[object Array]';
        if (!isArray(this)) {
            throw new TypeError("`this` must be Array, not " + typeof this);
        if (arguments.length === 0) {
            throw new TypeError("Missing required argument(s)");
    ...
    
  3. range()
    Array.prototype.range = function() {
      var min = null,
        max = null,
        sum = null,
        i, len;
      for (i = 0, len = this.length; i < len; ++i) {
        var elem = this[i];
        sum += elem;
        if (min === null || min > elem) min = elem;
    ...
    
  4. range(end, step)
    Array.range = function (end, step) {
      var array = [];
      for (var i = step; i <= end; i += step) {
        array.push(i);
      return array;
    
  5. range(from, to)
    Array.prototype.range = function(from, to) {
      var result = []
      while (from <= to)
        result.push(from++)
      return result
    
  6. range(from, to)
    Array.prototype.range = function(from, to) {
      var i, result = [];
      for (i = from; i<= to; i++) {
        result.push(i);
      return result;
    };
    console.log([].range(1, 10));
    
  7. range(start, count)
    Array.range  = function(start, count) {
      var arr = [],
          val = start;
      while(count > 0) {
        arr.push(val);
        count--;
        val++;
      return arr;
    ...
    
  8. range(start, end)
    Array.range = function (start, end) {
      var a = [], i;
      for (i = start; i < end; i += 1) {
        a[i] = i;
      return a;