use reduce rather than explicit loop

reduce is far more succint and feels more functional-y