Question

Write a ruby algorithm that prints only words that begin with a capital letter Input a...

Write a ruby algorithm that prints only words that begin with a capital letter

Input

a = ['aA', 'Aa', 'red', 'Book']

Output

b = ['Aa', 'Book']

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program that takes a string of words, and prints out these words one per...
Write a program that takes a string of words, and prints out these words one per line in a rectangular format (using # shape). The output must be properly formatted. (Save your script as tabularFormat.py and tabularFormat.txt) If the input is: “Roses are red, sky is blue, I mind my own business, why can’t you!”The output would be: (With Comments )
Write a function that accepts a line of text and a single letter as input (case...
Write a function that accepts a line of text and a single letter as input (case insensitive) and returns the number of times the letter is the first character of a word. Note your program should be able to handle different cases. And check if the user input is a single letter. Example: Input text = "When the SUN rises at dawn, the chicken flies into the window." Input letter = "t" Output = "The letter t has appeared 3...
Write a java script function that accepts a string as input and prints the 3rd, 5thand...
Write a java script function that accepts a string as input and prints the 3rd, 5thand 7thwordof input string with ‘-‘ in between the words. Spaces at the start and end of string must be ignored. it done html and javascript and plz do it in simple way
Write a c++ program that prints all possible distinct “words” that can be obtained by permuting...
Write a c++ program that prints all possible distinct “words” that can be obtained by permuting the letters of the word input by users. (Note: A “word” here refers to a sequence of letters and need not be in the dictionary.) For example: Input word to find permutations: abc acb bac bca cba cab
Design an algorithm in pseudocode to determine whether any 5-letter word is a palindrome. Palindromes are...
Design an algorithm in pseudocode to determine whether any 5-letter word is a palindrome. Palindromes are words or sentences that read the same backward or forward. For example, “kayak” is a palindrome while “meter” is not. Ask the user to input 5 characters. You will need five separate variables to store these five characters. After obtaining the characters, compare the characters to determine if the word is a palindrome and output an appropriate message.
Using PHP: Write a function that: Given a numerical parameter in input, computes and prints all...
Using PHP: Write a function that: Given a numerical parameter in input, computes and prints all the prime numbers up to that value. Example: If input parameter is 10, output is "2, 3, 5, 7" If input parameter is 100, output is "2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97" Write a "tester function" that: Given a specific subset of inputs, tests the...
Project File Processing. Write a program that will read in from input file one line at...
Project File Processing. Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespaces,...
Write a recursive algorithm in a pseudo code, Min-Max, for finding both the minimum and the...
Write a recursive algorithm in a pseudo code, Min-Max, for finding both the minimum and the maximum elements in an array A of n elements. Your algorithm calls itself only once within the algorithm and should return a pair (a, b) where a is the minimum element and b is the maximum element. Algorithm Min-Max(A, n) Input: an Array A of n elements Output: a pair of (a, b) where a is the minimum element and b is the maximum...
Finally, write a script named word_counts.sh that prints out how many words are on each line...
Finally, write a script named word_counts.sh that prints out how many words are on each line of standard input, as well as the total number of words at the end. The script should take no arguments. Instead, the script must work by reading every line of standard input (using a while loop) and counting the number of words on each line separately. The script is intended to work with standard input coming from a pipe, which will most often come...
Write a program (O(n), where n is the number of words) that takes as input a...
Write a program (O(n), where n is the number of words) that takes as input a set of words and returns groups of anagrams for those words. Complete your code here - For example, if the list is "debitcard", "elvis", "silent", "badcredit", "lives", "freedom", "listen", "levis", the output should be silent listen debitcard badcredit elvis lives levis Note that freedom has no anagram, and hence is not printed. ///////////////////////////////////////////////$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% anagram.cpp #include <iostream> #include <unordered_map> #include <vector> #include <algorithm> using namespace...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT