You will solve the following problems using map, filter, and reduce or
and combination of those 3. No loops of any kind are allowed.
Write a function to do each of the following. Each function should take a string as input and return a string as output.
- Replace A's with
4and E's with3in a string. - Remove all vowels from a string.
- Reverse a string.
- Reverse all words within a sentence.
Start with these Doctor Who Episodes:
const doctorWhoEpisodes = [
{"episode": "eleventh hour", "season": 5, "uk_ratings": 10.9, "doctor": 11, "writer": "moffat"},
{"episode": "blink", "season": 3, "uk_ratings": 6.62, "doctor": 10, "writer": "moffat"},
{"episode": "human nature", "season": 3, "uk_ratings": 7.74, "doctor": 10, "writer": "cornell"},
{"episode": "family of blood", "season": 3, "uk_ratings": 7.21, "doctor": 10, "writer": "cornell"},
{"episode": "silence in the library", "season": 4, "uk_ratings": 6.27, "doctor": 10, "writer": "moffat"},
{"episode": "forest of the dead", "season": 4, "uk_ratings": 7.84, "doctor": 10, "writer": "moffat"},
{"episode": "midnight", "season": 4, "uk_ratings": 8.05, "doctor": 10, "writer": "davies"},
{"episode": "a good man goes to war", "season": 6, "uk_ratings": 7.51, "doctor": 11, "writer": "moffat"},
{"episode": "let's kill hitler", "season": 6, "uk_ratings": 8.10, "doctor": 11, "writer": "moffat"},
{"episode": "Husbands of River Song", "season": 9, "uk_ratings": 7.69, "doctor": 12, "writer": "moffat"}
];- Write a
episodesForSeason(episodes, seasonNo)function that returns all episodes of a season given an array of all episode objects and the season number, and returns an array of episode objects which are of the matching season. - Write an
averageRating(episodes)function that returns the average rating of all episodes that are passed in. - Write a
highestRatingEpisode(episodes)function that returns the episode object that has the highest rating. - Write a
averageRatingForDoctor(episodes, doctorNo)function that returns the average rating for a particular doctor. - Write a
standardDeviation(episodes)function that returns the standard deviation of the ratings across the episodes.
You've seen how the array map method can be reimplemented as a simple function. Your challenge --- if you choose to accept it --- is to reimplement the array filter method. If you are not familiar with the filter method, that's okay.
The myFilter function takes 2 parameters:
- an array
- a function which takes one parameter that is one of the element of the array. It is expected to return either a truthy or falsey value.
myFilter will return a new array of elements, each of which must be in the
original array. Each element within the returned array would cause the
passed in function to yield a truthy value.
Example:
const names = ["Jill", "Kay", "Carlos", "Ilyana", "Solveig"];
const shortNames = myFilter(names, (name) => name.length < 5);
console.log(shortNames.join(", "));should output:
Jill, Kay