Skip to content

Commit b3c18db

Browse files
examples valid with Lua 5.4
Lua 5.4 removed math.pow, and made reassignment to loop variables a runtime error. We replace example code in gigasecond and run-length-encoding.
1 parent fe3f9fd commit b3c18db

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

exercises/practice/gigasecond/.meta/example.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
local gigasecond = {}
44

55
function gigasecond.anniversary(any_date)
6-
return os.date('!%x', any_date + math.pow(10, 9))
6+
return os.date('!%x', any_date + 10 ^ 9)
77
end
88

99
return gigasecond

exercises/practice/run-length-encoding/.meta/example.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ return {
1414
decode = function(s)
1515
local result = ''
1616
for length, c in s:gmatch('(%d*)(.)') do
17-
if length == '' then
18-
length = 1
19-
end
20-
result = result .. c:rep(length)
17+
local n = (length == '') and 1 or tonumber(length)
18+
result = result .. c:rep(n)
2119
end
2220
return result
2321
end

0 commit comments

Comments
 (0)