const numbers = [1,2,3,4,5,6]
// reduce's callback function's returned value is automatically assigned to the accumulator.
numbers.reduce((acc, n) => acc * n, 1)
> 720
numbers.reduce((acc, n) => acc + n, '')
> '123456'
// acc is automatically assigned, so the following version is verbose.
// keep this verbose-version just for reminding myself.
// useless version
numbers.reduce((acc, n) => {acc[n]=n*n; return acc;}, {})
> { '1': 1, '2': 4, '3': 9, '4': 16, '5': 25, '6': 36 }
// compact version
numbers.reduce((acc, n) => ({...acc, [n]:n*n }), {})
> { '1': 1, '2': 4, '3': 9, '4': 16, '5': 25, '6': 36 }
// compact version
numbers.reduce((acc, n) => [...acc, n*n], [])
> [ 1, 4, 9, 16, 25, 36 ]