Write a function disemvowel(string), which takes in a string, and
returns that string will all the vowels removed. Treat “y” as a
consonant.
def disemvowel(string)
i = 0
while i < string.length
strings = string.split
[string[i] == "a" || string[i] == "e" || string[i] == "i" ||
string[i] == “o” || string[i] == “u”].delete
strings = string.join
end
return strings
end
I feel that “Strings” variable is unnecessary.
And “Split” “Join” seems unecessary.
dbhatt
August 24, 2015, 9:27pm
#2
personally I’d just do string.gsub(/[aeiou]/,’’)
dbhatt
August 25, 2015, 5:06am
#3
Joel P. wrote in post #1178119:
personally I’d just do string.gsub(/[aeiou]/,’’)
For my exercise, I have to do it as long as possible.
However, it’s not working. It won’t run the method.
dbhatt
August 25, 2015, 7:39am
#4
hi Dhaval B.,
try this
a=“Dhaval B.”
puts a.split(’’).delete_if{|x| [‘a’,‘e’,‘i’,‘o’,‘u’].include?x}.join
output
“Dhvl Bhtt”
dbhatt
August 25, 2015, 1:08pm
#5
Dhaval B. wrote in post #1178134:
For my exercise, I have to do it as long as possible.
def disemvowel(string)
i = 0
strings = string.split
result=""
while i < string.length
car = string[i]
result << car unless car == “a” || car == “e” ||
car == “i” || car == “o” || car == “u”
i+=1
end
result
end
p disemvowel(“you should change of teacher…”)
dbhatt
August 25, 2015, 11:41pm
#6
Regis d’Aubarede wrote in post #1178148:
i+=1
nahh, too short.
x = rand()
i = i + (Math.sin(x)**2 + Math.cos(x)**2).to_i