Nodejs Array Range rangeArray(startIndex, endIndex)

Here you can find the source of rangeArray(startIndex, endIndex)

Method Source Code

/**/*www. ja  va2 s.com*/
 * Returns an array with elements populated between the specified range(INCLUSIVE)
 *
 * @extends Array
 * @function rangeArray
 * @param {number} startIndex - Start element of the array to be built
 * @param {number} endIndex - End element of the array to be built
 * @return {array}
 *
 * Examples:
 *    (new Array()).rangeArray(0, 5);
 *    ([]).rangeArray(0, 5);
 *    => [0, 1, 2, 3, 4, 5]
 */
Array.prototype.rangeArray = function (startIndex, endIndex) {
  var arr = []
  for(var i=startIndex; i<endIndex; i++) {
    arr.push(i);
  }
  return arr;
}

Related

  1. range(start, count)
    Array.range  = function(start, count) {
      var arr = [],
          val = start;
      while(count > 0) {
        arr.push(val);
        count--;
        val++;
      return arr;
    ...
    
  2. range(start, end)
    Array.range = function (start, end) {
      var a = [], i;
      for (i = start; i < end; i += 1) {
        a[i] = i;
      return a;
    
  3. range(start, end)
    Array.prototype.range = function(start, end) {
        var result = [];
        for (var i = start; i <= end; i++) {
            result.push(i);
        return result;
    
  4. range(start,end)
    Array.prototype.range = function(start,end){
      return Array.apply(null, Array(end-start+1)).map(function (_, i){
          return start+i;
      });
    };
    
  5. range(start,end,step)
    Array.prototype.range = (start,end,step)=>{
        const stepVal = step || 1
        const set = new Set()
        for (var i=start;i<=end;i=i+stepVal){
            set.add(i)
        return [...set]
    Set.prototype.union = function (set) {
    ...