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
# Return the argument with all its lowercase characters removed. | |
def destructive_uppercase(str) | |
var x | |
str.each_char do { |el| | |
if el === [A..Z] | |
el += x } | |
end | |
return x |
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 destructive_uppercase(str) | |
x = "" | |
str.each_char do |el| | |
if el === [A..Z] | |
el += x | |
end | |
return x |
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 destructive_uppercase(str) | |
x = "" | |
str.chars.each do |el| | |
if el == [A..Z] | |
el += x | |
end | |
return x |
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 devowel(str) | |
vowels = ["a", "e", "i", "o", "u"] | |
new_str = "" | |
# We turn the string into an array of characters using chars. | |
# An alternative to this is the method each_char (covered below!) | |
str.chars.each do |ch| | |
next if vowels.include?(ch.downcase) | |
# the code below is only reachable when ch is a consonant | |
new_str += ch |
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 destructive_uppercase(str) | |
x = "" | |
str.chars.each do |el| | |
if el == [A..Z] | |
el += x | |
end | |
end | |
return x |
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 destructive_uppercase(str) | |
x = "" | |
str.chars.each do |el| | |
if el === [A..Z] | |
x += el | |
end | |
end | |
end | |
return x |
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
# Return the middle character of a string. Return the middle two characters if | |
# the word is of even length, e.g. middle_substring("middle") => "dd", | |
# middle_substring("mid") => "i" | |
def middle_substring(str) | |
finalString = "" | |
if (str.length % 2) == 0 | |
x = str.chars | |
finalString += x[(x.(length/2).ceil] | |
finalString += x[x.(length/2).floor] |
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
# Return the middle character of a string. Return the middle two characters if | |
# the word is of even length, e.g. middle_substring("middle") => "dd", | |
# middle_substring("mid") => "i" | |
def middle_substring(str) | |
finalString = "" | |
if (str.length % 2) == 0 | |
x = str.chars | |
finalString += x[((x.length)/2).ceil] | |
finalString += x[((x.length)/2).floor] |
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
# Write a method that returns a boolean indicating whether the argument is | |
# prime. | |
def prime?(num) | |
(1..num).each do |i| | |
if (num % i == 0 && i != 1 && i != num) || (num == 1) | |
return false | |
end | |
end | |
return true; | |
end |
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
# Write a method that returns a boolean indicating whether the argument is | |
# prime. | |
def prime?(num) | |
(1..num).each do |i| | |
if (num % i == 0 && i != 1 && i != num) || (num == 1) | |
return false | |
end | |
end | |
return true; |
OlderNewer