Skip to content

Commit

Permalink
feat: v0.55.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Chunjee committed Dec 2, 2022
1 parent 3a55af6 commit b52af48
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
42 changes: 42 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4482,6 +4482,48 @@ A.map([["a", 3], ["c", 1]], A.propertyOf(object))



## .range
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.


#### Example

```autohotkey
A.range(4)
; => [0, 1, 2, 3]
A.range(-4)
; => [0, -1, -2, -3]
A.range(1, 5)
; => [1, 2, 3, 4]
A.range(0, 20, 5)
; => [0, 5, 10, 15]
A.range(0, -4, -1)
; => [0, -1, -2, -3]
A.range(1, 4, 0)
; => [1, 1, 1]
A.range(0)
; => []
```



## .stubArray
This method returns a new empty array.

Expand Down
44 changes: 43 additions & 1 deletion export.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ class biga { ; --- Static Variables --- static throwExceptions := true stati
l_array := []
for key, value in param_collection {
vItaree := param_predicate.call(value)
if (!l_array[vItaree]) {
; use .hasKey because modern array methods such as .some can return true/1
if (!l_array.hasKey(vItaree)) {
; start counter at 1 if first encounter
l_array[vItaree] := 1
} else {
Expand Down Expand Up @@ -2894,6 +2895,47 @@ class biga { ; --- Static Variables --- static throwExceptions := true stati
internal_propertyOf(param_object,param_path) {
return this.property(param_path).call(param_object)
}
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
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 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
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 l_array
}
stubArray() {
return []
}
Expand Down
20 changes: 20 additions & 0 deletions test/test-all.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ wordOccurances := A.countBy(["one", "two", "three", "one", "two", "three"], A.to
assert.equal(wordOccurances, {"one": 2, "two": 2, "three": 2})
wordOccurances := A.countBy(["one", "two", "three", "one", "two", "three"])
assert.equal(wordOccurances, {"one": 2, "two": 2, "three": 2})

assert.group(".every")
assert.label("default tests")
assert.false(A.every([true, 1, false, "yes"], A.isBoolean))
Expand Down Expand Up @@ -2359,6 +2360,25 @@ assert.test(A.map(["a[3]", "c[1]"], A.propertyOf(object)), [2, 0])
assert.test(A.map([["a", 3], ["c", 1]], A.propertyOf(object)), [2, 0])


; omit

assert.group(".range")
assert.label("default tests")
assert.test(A.range(4), [0, 1, 2, 3])

assert.test(A.range(-4), [0, -1, -2, -3])

assert.test(A.range(1, 5), [1, 2, 3, 4])

assert.test(A.range(0, 20, 5), [0, 5, 10, 15])

assert.test(A.range(0, -4, -1), [0, -1, -2, -3])

assert.test(A.range(1, 4, 0), [1, 1, 1])

assert.test(A.range(0), [])


; omit

assert.group(".stubArray")
Expand Down

0 comments on commit b52af48

Please sign in to comment.