median ← {
⍝ Compute the median of a vector of numbers.
vals ← ⍵ ⍝ vals is the input vector of numbers.
n ← ≢ vals ⍝ n is the number of values in the vector.
0 = n: ⍬ ⍝ If the vector is empty, return an empty vector.
vals ← vals[⍋vals] ⍝ Sort the values in ascending order.
1 = 2|n: vals[(n + 1) ÷ 2] ⍝ If n is odd, return the middle value.
0.5 × +/ vals[n ÷ 2] + vals[1 + n ÷ 2] ⍝ If n is even, return the average of the two middle values.
}