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

anagrams #3

Open
ChrisMuir opened this issue Mar 5, 2018 · 0 comments
Open

anagrams #3

ChrisMuir opened this issue Mar 5, 2018 · 0 comments

Comments

@ChrisMuir
Copy link
Contributor

Any interest in a function that determines if inputs are anagrams of each other? I created an anagrams pkg using Rcpp/c++, but in the process created pure base R versions of the functions that I'm not using. If interested I'd be happy to submit a PR....if not, no worries.

Here's the basic idea:

# Test for anagrams that are the same length as the input string.
chr_anagram("stac", c("cats are great", "tacs", "frogs", "cats", "ts"))
#> [1] FALSE  TRUE FALSE  TRUE FALSE

# Use arg "value" to return the values that are anagrams.
chr_anagram("stac", c("cats are great", "tacs", "frogs", "cats", "ts"), value = TRUE)
#> [1] "tacs" "cats"

# Use arg "any_len" to test for anagrams that are any length (either same length or sub-string).
chr_anagram("stac", c("cats are great", "tacs", "frogs", "cats", "ts"), any_len = TRUE)
#> [1]  TRUE  TRUE FALSE  TRUE FALSE

# Use arg "ignore_space" to make anagram searching insensitive to spaces.
chr_anagram("s t a c", c("cats are great", "t acs", "frogs", "ca   ts", "ts"), ignore_space = TRUE)
#> [1] FALSE  TRUE FALSE  TRUE FALSE

# Use arg "ignore_case" to make anagram searching insensitive to lower/upper case.
chr_anagram("STAc", c("catS are great", "tacs", "frogs", "CaTS", "ts"), ignore_case = TRUE)
#> [1] FALSE  TRUE FALSE  TRUE FALSE
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

No branches or pull requests

1 participant