aboutsummaryrefslogtreecommitdiff
path: root/challenge-278/deadmarshal/lua/ch-2.lua
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-07-20 12:33:42 +0100
committerGitHub <noreply@github.com>2024-07-20 12:33:42 +0100
commitd81b97819b40fef1af80b0d9585c9fc6b7147b5f (patch)
tree60a1ba6f99ddc149a30d73ebc7757daf5822b85f /challenge-278/deadmarshal/lua/ch-2.lua
parent65c93aa7401141c479d8ea993c3efba9b69ef9be (diff)
parent83c26b915df95865c54062ab5c1a04a916ac217a (diff)
downloadperlweeklychallenge-club-d81b97819b40fef1af80b0d9585c9fc6b7147b5f.tar.gz
perlweeklychallenge-club-d81b97819b40fef1af80b0d9585c9fc6b7147b5f.tar.bz2
perlweeklychallenge-club-d81b97819b40fef1af80b0d9585c9fc6b7147b5f.zip
Merge pull request #10459 from deadmarshal/TWC278
TWC278
Diffstat (limited to 'challenge-278/deadmarshal/lua/ch-2.lua')
-rw-r--r--challenge-278/deadmarshal/lua/ch-2.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/challenge-278/deadmarshal/lua/ch-2.lua b/challenge-278/deadmarshal/lua/ch-2.lua
new file mode 100644
index 0000000000..d368132923
--- /dev/null
+++ b/challenge-278/deadmarshal/lua/ch-2.lua
@@ -0,0 +1,16 @@
+#!/usr/bin/env lua
+
+local function reverse_string(s,e)
+ assert(type(s) == 'string' and
+ type(e) == 'string','s and e must be strings!')
+ local t,idx = {},string.find(s,e,1,true)
+ if idx == nil then return s end
+ for i=1,idx do t[#t+1] = s:sub(i,i) end
+ table.sort(t)
+ return table.concat(t,'') .. s:sub(idx+1,#s)
+end
+
+print(reverse_string('challenge','e'))
+print(reverse_string('programming','a'))
+print(reverse_string('champion','b'))
+