Write a ruby algorithm that prints only words that begin with a capital letter
Input
a = ['aA', 'Aa', 'red', 'Book']
Output
b = ['Aa', 'Book']
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
code screen shot
copy to code
main.rb
#initialize the array
array = ['aA', 'Aa', 'red', 'Book']
#loop for each element in the array
array.each do |i|
#now check if first character is same as upper case of it
if i[0]==i[0].upcase
#if yes print it
puts i
#end of if condition
end
#end of array loop
end
output
Get Answers For Free
Most questions answered within 1 hours.