Question
Scala Programming Who let the dogs out, really? You are given text as an input string which talks about people letting dogs out. We would
Scala Programming
Who let the dogs out, really?
You are given text as an input string which talks about people letting dogs out. We would like to extract the list of all the strings that let the dogs out.
In other words, we look for all substrings of the form ..... let the dogs out and return all the words that occur immediately before the phrase "let the dogs out" in the input string.
Example
" The society let the dogs out Letting the dogs out is the very essence of our democracy I let the dogs out You let the dogs out My grandma let the dogs out Your dad let the dogs out We all let the dogs out The dogs let themselves out"
Your function should return the list List("society", "I", "You", "grandma', "dad", "all").
Use the functions that you have implemented so far in your solution.
- Use splitIntoWords to convert it into a list of words.
- Use findPatternIndicesInList to search for all indices where the pattern List("let", "the", "dogs", "out") appears.
- Subtract 1 from all the indices that are > 0 to extract the result.
In [ ]:
def whoLetTheDogsOut(txt: String): List[String] = {
// YOUR CODE HERE
???
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started