aboutsummaryrefslogtreecommitdiff
path: root/challenge-331/hvukman/lua/331_p1.lua
blob: bf882dab1df4cd9d697439897f739566daaf7b40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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")