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 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
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,...
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...
Write a alogorithem for delete a max heap tree. . Give an efficient algorithm for the...
Write a alogorithem for delete a max heap tree. . Give an efficient algorithm for the following problem. Tree-Successor • Input: A BST T and a node a of T • Output: The node b of T containing the smallest key larger than a.key. If there is no such b, the output should be NIL.
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
Please write a function three(string) that return a string that all three-letter words are replaced by...
Please write a function three(string) that return a string that all three-letter words are replaced by ***.   For example: three("submit only one question per post.  ") return: "submit only *** question *** post. " Please using Python!
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT