-
Notifications
You must be signed in to change notification settings - Fork 1
/
Array.ahk
41 lines (38 loc) · 1.02 KB
/
Array.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#Requires AutoHotKey 2.1-alpha.4
HasValue(haystack, needle) { ; Checks if a value exists in an array
;FoundPos := HasValue(Haystack, Needle)
if !(IsObject(haystack)) {
return -1
; throw ValueError("Bad haystack!", -1, haystack)
}
for index, value in haystack
if (value = needle)
return index
return 0
}
; autohotkey.com/boards/viewtopic.php?p=537511#p537526
Array.Prototype.DefineProp("ForEach", {call:_ArrayForEach})
_ArrayForEach(this, func) { ; Applies a function to each key/value pair in the Array
; @param func callback function with arguments Callback(value[, key, array])
; @returns {Array}
if not HasMethod(func) {
throw ValueError("ForEach: func must be a function", -1)
} else {
for i, v in this {
func(v, i, this)
}
return this
}
}
joinArr(arrays*) {
outArr := []
for i,arr in arrays {
if not type(arr) = 'Array' {
throw ValueError('Argument #' i ' is not an array!', -1)
}
for el in arr {
outArr.Push(el)
}
}
return outArr
}