aboutsummaryrefslogtreecommitdiff
path: root/challenge-331/hvukman/lua/331_p1.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-331/hvukman/lua/331_p1.lua')
-rw-r--r--challenge-331/hvukman/lua/331_p1.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-331/hvukman/lua/331_p1.lua b/challenge-331/hvukman/lua/331_p1.lua
new file mode 100644
index 0000000000..bf882dab1d
--- /dev/null
+++ b/challenge-331/hvukman/lua/331_p1.lua
@@ -0,0 +1,20 @@
+-- http://lua-users.org/wiki/StringTrim
+function Trim(s)
+ return s:match'^()%s*$' and '' or s:match'^%s*(.*%S)'
+end
+
+function Last_length (X)
+ local words = {}
+
+ for word in Trim(X):gmatch("%w+") do
+ table.insert(words, word)
+ end
+
+ local last_word = words[#words]
+ print(#last_word)
+
+end
+
+Last_length("The Weekly Challenge")
+Last_length(" Hello World ")
+Last_length("Let's begin the fun")