Other solution using standard library higher order functions