R/multiply_effects.R

Defines functions multiply_effects

multiply_effects <- function(str1, str2) {
  # helper function, multiply letter strings
  # E.g. multiply_effects("ABC", "CDE") --> "ABDE"
  
  counts <- table(strsplit(paste0(str1,str2), ""))
  # If the number of occurrences is odd, that letter stays (was not canceled)
  reduced <- paste0(names(counts[counts %% 2 == 1]), collapse="")
  return(reduced)
}
cbreenmachine/wiscR documentation built on Jan. 26, 2022, 9:10 a.m.