Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extracts range function to utils file.
- Loading branch information
1 parent
1a5d3b8
commit 56ceff2
Showing
3 changed files
with
24 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
function range(start, stop, step) { | ||
if (typeof stop == 'undefined') { | ||
// one param defined | ||
stop = start; | ||
start = 0; | ||
} | ||
|
||
if (typeof step == 'undefined') { | ||
step = 1; | ||
} | ||
|
||
if ((step > 0 && start >= stop) || (step < 0 && start <= stop)) { | ||
return []; | ||
} | ||
|
||
var result = []; | ||
for (var i = start; step > 0 ? i < stop : i > stop; i += step) { | ||
result.push(i); | ||
} | ||
|
||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters