123456789101112131415161718192021222324 |
- #unittest {
- name: "List reduce.";
- result: true;
- };
- func main() {
- var list = [0, 1, 2, 3, 4, 5, 6]
- func x(a, b) {
- return a - b
- }
- var reduced = list.reduce(-1, x) //-22
- if (reduced != -22) {
- return false
- }
- var list2 = ["this","is","a","test"]
- func y(a, b) {
- return a + b
- }
- reduced = list2.reduce("", y)
- if (reduced != "thisisatest") {
- return false
- }
- return true
- }
|