aboutsummaryrefslogtreecommitdiff
path: root/challenge-096/tyler-wardhaugh/lua/ch-1.lua
blob: 6538be9718e7b855a0ab08c048a884a4d8f1fa6c (plain)
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
#!/usr/bin/env lua

local t1 = {}
t1.DEFAULT_INPUT = 'The Weekly Challenge'

function t1.reverse_words(s)
  local words = {}
  for word in s:gmatch('%S+') do
    table.insert(words, 1, word)
  end
  return table.concat(words, ' ')
end

function t1.run(args)
  local s
  if #args > 0 then
    s = args[1]
  else
    s = t1.DEFAULT_INPUT
  end

  print(t1.reverse_words(s))
end

return t1