#' Detects and return the existence of two pairs
#'
#' @param cards A list of objects from the S4 class 'card'.
#'
#' @return list containing a logical representing if there are two pairs,
#' and the pairs themselves if they exist.
#' @export
#'
#' @examples
exists_two_pair <- function(cards){
pair <- exists_n_kind(cards,2)
if (!pair$logical) return(list("logical" = FALSE))
pair <- pair$cards
cards <- remove_cards(cards,pair)
pair2 <- exists_n_kind(cards,2)
if(!pair2$logical) return(list("logical" = FALSE))
pair2 <- pair2$cards
cards <- remove_cards(cards,pair2)
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_card <- names(values)[1] %>% as.numeric() %>% cards[.]
cards <- c(pair,pair2,top_card)
return(list("logical" = FALSE,"cards" = cards))
}
cards <- new_cards(7,new_deck())[-8]
cards <- exists_two_pair(cards)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.