First commit
This commit is contained in:
18
exercises/ch04/ex4_3.lua
Normal file
18
exercises/ch04/ex4_3.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
local function insert(str, i, o)
|
||||
local first_half = str:sub(1, i - 1)
|
||||
local latter_half = str:sub(i, -1)
|
||||
return first_half .. o .. latter_half
|
||||
end
|
||||
|
||||
local function tests()
|
||||
local res = insert("hello world", 1, "start: ")
|
||||
print(('insert("hello world", 1, "start: ") --> %s'):format(res))
|
||||
|
||||
res = insert("hello world", 7, "small ")
|
||||
print(('insert("hello world", 7, "small ") --> %s'):format(res))
|
||||
|
||||
res = insert("hello world", 12, "!")
|
||||
print(('insert("hello world", 12, "!") --> %s'):format(res))
|
||||
end
|
||||
|
||||
tests()
|
||||
Reference in New Issue
Block a user