diff options
Diffstat (limited to 'toot-toot.tlv')
-rw-r--r-- | toot-toot.tlv | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/toot-toot.tlv b/toot-toot.tlv index b03d209..375d503 100644 --- a/toot-toot.tlv +++ b/toot-toot.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 @@ -249,6 +250,21 @@ > 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) > for k, v in pairs(b) do |