namespace UsingReduce { function reduce < T > ( items , init , op ) { let result = init ; for ( const item of items ) { result = op ( result , item ) ; } return result ; } let numbers = [ 1 , 2 , 3 , 4 , 5 ] ; let product = reduce ( numbers , 1 , ( x , y ) => x * y ) ; let strings = [ "apple" , "orange" , "peach" ] ; let longString = reduce ( strings , "" , ( x , y ) => x + y ) ; }