Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Differential Equations With Boundary-Value Problems

Authors: Dennis G Zill, Brad Strong, Michael Cullen

7th Edition

1111798524, 9781111798529

More Books

Students also viewed these Mathematics questions

Question

Write down the Limitation of Beer - Lamberts law?

Answered: 1 week ago

Question

Discuss the Hawthorne experiments in detail

Answered: 1 week ago

Question

Explain the characteristics of a good system of control

Answered: 1 week ago

Question

State the importance of control

Answered: 1 week ago