Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reverse input string if input string length is less than 4
def string_rev_if_4(input)
return input.reverse if input.length < 4
input
end
string_rev_if_4("he") # "eh"
string_rev_if_4("hel") # "leh"
string_rev_if_4("hell") # "hell"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment