Reduce the items in an iterable down to a single instance of initial type, returning the final result result of the reduction
function reduce(predicate, initial) {
    return function (iterable) {
        let index = 0;
        let prevState = initial;
        for (const value of iterable) {
            prevState = predicate(prevState, value, index);
            index = index + 1;
        }
        return prevState;
    };
}