CS 119 Lab 3 – Higher Order Function
Objectives
Perform the following tasks in the order given.
| Assignment: Use every to write a function exaggerate that takes a sentence and doubles all numbers in the sentence and replaces the word "good" with the word "great" and the word "bad" with the word "terrible" > exaggerate (sent
"I ate 3 good hotdogs") Hint: The function applied to each word in the sentence should check for the special cases and return the appropriate results. Otherwise it should just return the word unchanged. |
|
Assignment: Use keep to write a function firstLast which returns the words in a sentence whose first and last letters are the same.
> firstLast (sent "california ohio nebraska alabama maryland") |
|
Assignment: Use accumulate to hyphenate a sentence of words together. > hyphenate (sent "one thousand
forty five") Hint: The function used as an argument to accumulate must take two words and combine them. |
|
Assignment: Write a function acronym using only every, keep, and accumulate. >
acronym (sent "reduced instruction set computer") > acronym (sent "foundations of computer science") Small connecting words like "of" are not part of the acronym. You may use the function realWord to determine if a word is irrelevant or not. |