Add type signatures for all functions and refactor to single var declaration. Add specs for reduceRight() function.