DEV Community

Discussion on: Array.reverse() - for reversing an array

Collapse
 
jonrandy profile image
Jon Randy 🎖️

Some other (non-mutating) alternatives with reduce:

const reverse = arr => arr.reduce((r, i) => [i, ...r], [])
const reverse2 = arr => arr.reduce((r, i) => (r.unshift(i), r), [])
Enter fullscreen mode Exit fullscreen mode
Collapse
 
dillionmegida profile image
Dillion Megida

this took me some time to understand haha