(argmax (λ(c) (string-length (customer-name c))) customers)
Haskell has argmaxBy: http://hackage.haskell.org/packages/archive/list-extras/0.3....
If your language doesn't have argmax, fold the list with the best value, like this in lisp:
(define (my-argmax fun lst) (foldl (λ(prev-max elt) (if (< (fun prev-max) (fun elt)) elt prev-max)) (car lst) (cdr lst)))
Haskell has argmaxBy: http://hackage.haskell.org/packages/archive/list-extras/0.3....
If your language doesn't have argmax, fold the list with the best value, like this in lisp:
No extra space usage, no temporary values, no sorting; all in O(N) time. :)