Compute minimax of an array
Dyalog APL, 4 bytes
⌊/⌈/
This is a monadic function train that expects array and integer as right and left arguments, resp.
Try it with TryAPL.
How it works
A train of two functions is an atop, meaning that the right one is called first (with both arguments), then the left one is called on top of it (with the result as sole argument).
A monadic f/
simply reduces its argument by f
. However, if called dyadically, f/
is n-wise reduce, and takes the slice size as its left argument.
⌊/⌈/ Monadic function. Right argument: A (array). Left argument: n (list)
⌈/ N-wise reduce A by maximum, using slices of length n.
⌊/ Reduce the maxima by minimum.
CJam (11 bytes)
{ew::e>:e<}
Online demo
Ruby 39 bytes
->(x,n){x.each_slice(n).map(&:max).min}
Where x is the array and n is the number to chunk the array by.