From dd7da2c62ae1f53069e5bf07ea92861218da0c41 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 27 Mar 2022 10:53:41 -0700 Subject: helper: count --- life.tlv | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'life.tlv') diff --git a/life.tlv b/life.tlv index e35fd59..eba123f 100644 --- a/life.tlv +++ b/life.tlv @@ -236,6 +236,7 @@ >end - __teliva_timestamp: original count_letters: + >-- TODO: handle unicode >function count_letters(s) > local result = {} > for i=1,s:len() do @@ -248,6 +249,21 @@ > end > return result >end +- __teliva_timestamp: original + count: + >-- turn an array of elements into a map from elements to their frequency + >-- analogous to count_letters for non-strings + >function count(a) + > local result = {} + > for i, v in ipairs(a) do + > if result[v] == nil then + > result[v] = 1 + > else + > result[v] = result[v] + 1 + > end + > end + > return result + >end - __teliva_timestamp: original union: >function union(a, b) -- cgit 1.4.1-2-gfad0 mor/getwtxt/refs/?h=v0.4.11&id=711012ec003ffe8393f1e41d04eace71cbb5fe4c'>refs log tree commit diff stats
path: root/handlers_test.go
blob: b4e9096dacd8e09f0f19cee08b86bab44bcd6855 (plain) (blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116