79669288

Date: 2025-06-17 14:42:55
Score: 1
Natty:
Report link

Here is what finally worked with any string (I called it "final"):

final <- "B,C,A,C,C,A,B"

func_ignore_last_A <- function(seq) {
  
  if (length(seq) > 0 && !is.na(seq)) {
    vec <- str_split(seq, ",")[[1]]
    if ("A" %in% vec) {
      last_a_index <- tail(which(vec == "A"), 1)
      vec <- vec[-last_a_index]
    }
    return(paste(vec, collapse = ","))
  } else {
    return(seq)
  }
}

func_ignore_last_A(final)
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: HelloBiology