Lua, just as a series of string operations:
local function solution(text) return text:lower() :gsub("%A+", "") :gsub("%a", function(n) return " " .. 1 + n:byte() - string.byte("a") end) :sub(2) end
Lua, written with a loop and so a bit less wasteful:
local function solution(text) local ns = {} for a in text:gmatch("%a") do table.insert(ns, 1 + a:lower():byte() - string.byte("a")) end return table.concat(ns, " ") end
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Lua, just as a series of string operations:
Lua, written with a loop and so a bit less wasteful: