-
Notifications
You must be signed in to change notification settings - Fork 10
/
union.ahk
39 lines (28 loc) · 943 Bytes
/
union.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
union(param_arrays*) {
; prepare
l_array := []
; create
for key, array in param_arrays {
if (isObject(array)) {
l_array := this.concat(l_array, array)
} else {
l_array.push(array)
}
}
return this.uniq(l_array)
}
; tests
assert.test(A.union([2], [1, 2]), [2, 1])
; omit
assert.test(A.union(["Fred", "Barney", "barney", "barney"]), ["Fred", "Barney", "barney"])
assert.test(A.union("hello!"), ["hello!"])
assert.label("Arrays with no common elements")
assert.test(A.union([1, 2, 3], [4, 5, 6]), [1, 2, 3, 4, 5, 6])
assert.label("Arrays with some common elements")
assert.test(A.union([1, 2, 3], [3, 4, 5]), [1, 2, 3, 4, 5])
assert.label("Arrays with all elements identical")
assert.test(A.union([1, 2, 3], [1, 2, 3]), [1, 2, 3])
assert.label("Arrays with identical elements but in different orders")
assert.test(A.union([1, 2, 3], [3, 2, 1]), [1, 2, 3])
assert.label("Empty arrays")
assert.test(A.union([], []), [])