Question: Extend the function `sentence.flipper()` so that it is vectorized, i.e., if the input `str` is a vector of strings, then this function should return a

Extend the function `sentence.flipper()` so that it is vectorized, i.e., if the input `str` is a vector of strings, then this function should return a vector where each element is a string that is flipped in accordance with the description above. Hint: there is certainly more than one way to modify `sentence.flipper()` so that it works over vectors. But look out for a simple strategy---you already know that `sentence.flipper()` works over single strings, so now just do something to apply this strategy over each element of a vector. Once this is done, your function should be producing outputs on the test cases below that match those described in the comments.

```{r, error=TRUE}

# Redefine sentence.flipper() here

sentence.flipper = function(str) {

paste(sapply(strsplit(strsplit(str, '\\s+')[[1]], ''),

function(x) paste(rev(x), collapse = '')), collapse = ' ')

}

# Should be "olleh ssenkrad ym dlo dneirf",

#"ev'i emoc ot kaeps htiw uoy niaga"

sentence.flipper(c("hello darkness my old friend",

"i've come to speak with you again"))

# Should be "reven annog evig uoy pu",

#"reven annog tel uoy nwod",

#"reven annog nur dnuora dna tresed uoy"

sentence.flipper(c("never gonna give you up",

"never gonna let you down",

"never gonna run around and desert you"))

```

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!