Last active
March 15, 2018 17:08
-
-
Save ysnerdem/ce68442cda9f5c5b995ce2bb3434378c to your computer and use it in GitHub Desktop.
RemoveSpacesFromString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_spaces(str) | |
result = "" | |
str.each_char {|letter| result << letter if letter != " "} | |
result | |
end | |
#Alternative | |
def remove_spaces_v2(str) | |
str.delete! ' ' | |
str | |
end | |
puts "Enter a string" | |
str = gets | |
remove_spaces(str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment