Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reverse-string #303

Merged
merged 2 commits into from
Jan 7, 2024
Merged

Add reverse-string #303

merged 2 commits into from
Jan 7, 2024

Conversation

colinleach
Copy link
Contributor

For week 2 of #48in24, as discussed.

No approaches yet. Once this one is merged, I'll do that separately and PR it for discussion. The first one is often the most trouble.

Copy link
Member

@jonmcalder jonmcalder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - this looks great!

For the example solution, my preference would be:

reverse <- function(text) {
  strsplit(text, "") |>
    lapply(rev) |>
    sapply(paste, collapse = "")
}

because it'll handle vector text input, and because (these days) I think use of the native pipe is often preferable to assigning / naming intermediate objects (at least for shorter chains of operation - though this is probably a question of style / readability rather than what's idiomatic in R).

Not a big deal, so happy for you to leave this as is (i.e. change it only if you wish to do so after seeing this).

But another reason I thought it worth mentioning is because it could be worth exploring vectorised vs non-vectorised solutions in one or more of the performance articles. I'm considering doing so for leap.

(in the above case and in general, depending on implementation details, non-vectorised solutions will be faster for single inputs and slower for multiple inputs)

@colinleach
Copy link
Contributor Author

colinleach commented Jan 7, 2024

Your version is, of course, much better. I changed the example.R.

@colinleach colinleach merged commit 5e57f5a into exercism:main Jan 7, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants