Javascript: reduce

Xuda Lu
1 min readOct 9, 2019

--

the sequence different and the print also different.

x is accumulator , y is currentValue

t= [“aa”,”bb”,”cc”,”dd”]

1 t.reduce((x,y)=>x+y)
“aabbccdd”

2 t.reduce((x,y)=>x+y,”mm”)
“mmaabbccdd”

3 t.reduce((x,y)=>y+x,”mm”)
“ddccbbaamm”

--

--

Xuda Lu
Xuda Lu

No responses yet