Question
- **6d.**(0.3 point) Define a function `sentence.scrambler()` that operates similarly to to `sentence.flipper()`, but which randomly scrambles the order of characters in each word, instead
- **6d.**(0.3 point) Define a function `sentence.scrambler()` that operates similarly to to `sentence.flipper()`, but which randomly scrambles the order of characters in each word, instead of deterministically reversing them. The function `sentence.scrambler()` should be vectorized, just like the current version of `sentence.flipper()`. Hint: you can use `browser()` at any point if you run into bugs in your development, or simply to see how your function is handling certain test inputs. Also, the implementation of `sentence.scrambler()` should be pretty similar to `sentence.flipper()`; really, you just need to replace `word.flipper()` by a suitable function. Once done, run `sentence.scrambler()` on the test string below to display the output.
```{r, error=TRUE}
# Define sentence.scrambler() here
sentence.scrambler = function(str) {
paste(lapply(strsplit(strsplit(str, ",")[[1]], ""),
function(x) paste(rev(x), collapse = "")), collapse = " ")
}
sentence.scrambler(c("I have no theorems, well",
"I do have theorems, but none of them are named Fienberg's Theorem",
"Even if there were a Fienberg's Theorem, it probably wouldn't be important",
"What's important is the attitude, for what statistics is",
"and how it's recognized by other people outside of our field"))
```
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