Implement min_by and max_by functions

https://gist.github.com/mathiasverraes/0ec97dcd2d237eb25187