You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					22 lines
				
				573 B
			
		
		
			
		
	
	
					22 lines
				
				573 B
			| 
											3 years ago
										 | // Generate an integer Array containing an arithmetic progression. A port of
 | ||
|  | // the native Python `range()` function. See
 | ||
|  | // [the Python documentation](https://docs.python.org/library/functions.html#range).
 | ||
|  | export default function range(start, stop, step) { | ||
|  |   if (stop == null) { | ||
|  |     stop = start || 0; | ||
|  |     start = 0; | ||
|  |   } | ||
|  |   if (!step) { | ||
|  |     step = stop < start ? -1 : 1; | ||
|  |   } | ||
|  | 
 | ||
|  |   var length = Math.max(Math.ceil((stop - start) / step), 0); | ||
|  |   var range = Array(length); | ||
|  | 
 | ||
|  |   for (var idx = 0; idx < length; idx++, start += step) { | ||
|  |     range[idx] = start; | ||
|  |   } | ||
|  | 
 | ||
|  |   return range; | ||
|  | } |