Skip to content

Commit 8c76285

Browse files
authored
Merge pull request #261 from erichaney/examples_accumulate
Add examples for accumulate and accumulate2
2 parents dd5788b + 67d7627 commit 8c76285

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

examples/accumulate.janet

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(reduce + 0 [1 2 3 4]) # -> 10
2+
(accumulate + 0 [1 2 3 4]) # -> @[1 3 6 10]
3+
4+
(reduce + 0 []) # -> 0
5+
(accumulate + 0 []) # -> @[]
6+
7+
(reduce string "" ["J" "a" "n" "e" "t"]) # -> "Janet"
8+
(accumulate string "" ["J" "a" "n" "e" "t"]) # -> @["J" "Ja" "Jan" "Jane" "Janet"]

examples/accumulate2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(reduce2 + [1 2 3 4]) # -> 10
2+
(accumulate2 + [1 2 3 4]) # -> @[1 3 6 10]
3+
4+
(reduce2 + []) # -> nil
5+
(accumulate2 + []) # -> @[]
6+
7+
(reduce2 max [1 4 2 3 9 5]) # -> 9
8+
(accumulate2 max [1 4 2 3 9 5]) # -> @[1 4 4 4 9 9]

0 commit comments

Comments
 (0)