Here is my code:
local function firstLetter(str)
return string.sub(str, 1, 1)
end
local function lastLetter(str)
return string.sub(str, -1)
end
local function middleLetters(str)
return string.sub(str, 2, -2)
end
local str = "Happy Forever!"
print(firstLetter(str))
print(lastLetter(str))
print(middleLetters(str))
I was wondering if there is a better/easier method to getting what I need, and if I am even doing this correctly in the first place. I hope you guys can help. Thanks!

1 comment
In terms of efficiency,
middleLettersisn't a great function to use in palindrome-testing. That's because it needs to copy the entire middle section, making the resulting code O(n^2) which is extremely slow for long strings (e.g., 1000s or 10s of thousands of characters)