#' Detects and return the existence of a pair
#'
#' @param cards A list of objects from the S4 class 'card'.
#'
#' @return list containing a logical representing if there is a pair,
#' and the pair itself if there is one.
#' @importFrom magrittr %>%
#' @export
#'
exists_pair <- function(cards){
pair <- exists_n_kind(cards,2)
if (!pair$logical) return(list("logical" = FALSE))
pair <- pair$cards
cards <- remove_cards(cards,pair)
values <- c()
for ( i in 1:length(cards)){
values <- c(values,cards[[i]]@value)
}
names(values) <- paste(1:length(cards))
values <- sort(values,decreasing=TRUE)
top_cards <- names(values)[1:3] %>% as.numeric() %>% cards[.]
cards <- c(pair,top_cards)
return(list("logical" = TRUE,"cards" = cards))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.