Skip to content

Commit

Permalink
feat: .range
Browse files Browse the repository at this point in the history
  • Loading branch information
Chunjee committed Dec 2, 2022
1 parent e5262bc commit 3a55af6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/util/range.ahk
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
; ###incomplete###
range(param_start:=0,param_end:=0,param_step:=1) {
if (!this.isNumber(param_start) || !this.isNumber(param_end) || !this.isNumber(param_step)) {
this._internal_ThrowException()
}

; prepare
return_array := []
l_array := []
; A step of -1 is used if a negative start is specified without an end or step.
if (param_start < 0 && param_end == 0 && param_step == 1) {
param_step := -1
}
if (param_start == 0 && param_end == 0) {
return return_array
return l_array
}
if (param_end == 0) {
param_end := param_start
param_start := 0
}
l_currentStep := param_start
if (param_end > param_start) {
l_negativeFlag := true
}
; where step is 0, end at the array count
if (param_step == 0) {
zeroStepFlag := true
}


; create
while (param_start <= param_end || param_start == param_end) {
return_array.push(l_currentStep)
if (param_step == 0) {
param_start += 1
} else {
param_start += param_step
if (zeroStepFlag == true) {
loop, % param_end - 1 {
l_array.push(l_currentStep)
l_currentStep += param_step
}
} else {
while (l_currentStep != param_end) {
l_array.push(l_currentStep)
l_currentStep += param_step
}
}
return return_array
return l_array
}


Expand Down
11 changes: 11 additions & 0 deletions src/util/range.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end. A step of -1 is used if a negative start is specified without an end or step. If end is not specified, it's set to start with start then set to 0. The array's size is used as the end when a step of 0 is specified.


## Arguments
[start:=0] (number): The start of the range.
end (number): The end of the range.
[step:=1] (number): The value to increment or decrement by.


## Returns
(Array): Returns the range of numbers.

0 comments on commit 3a55af6

Please sign in to comment.