From b52af48059f5cabced7c8041b017d90619c9792e Mon Sep 17 00:00:00 2001 From: Shawn Brooker Date: Fri, 2 Dec 2022 14:49:45 -0800 Subject: [PATCH] feat: v0.55.0 --- docs/README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ export.ahk | 44 +++++++++++++++++++++++++++++++++++++++++++- test/test-all.ahk | 20 ++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 97f7e4d..cf8713b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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. diff --git a/export.ahk b/export.ahk index 8cfa86b..1b94c02 100644 --- a/export.ahk +++ b/export.ahk @@ -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 { @@ -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 [] } diff --git a/test/test-all.ahk b/test/test-all.ahk index bac3b8b..ac7f915 100644 --- a/test/test-all.ahk +++ b/test/test-all.ahk @@ -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)) @@ -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")