Best() takes a vector .x and a binary predicate function .f and returns the result of .f reduced over .x.

Best(.x, .f)

Arguments

.x

A vector.

.f

A binary predicate function.

Value

The best value in that vector, as determined by the binary predicate function.

Examples

# Simulate the behavior of max with numerics Best(1:10, function(x, y) return(x > y))
#> [1] 10
# Simulate the behavior of min with numerics Best(1:10, function(x, y) return(x < y))
#> [1] 1
# This comparison function prefers values that begin with l Best(letters, function(x, y) return(x[1] == "l"))
#> [1] "l"