DEV Community

loading...

Discussion on: JavaScript Quiz Part 2

Collapse
loilo profile image
Florian Reuschel • Edited

1) How to reverse a string using reduce method?

const rev = str => [...str].reduce((carry, char) => char.concat(carry), '')

Specifically, [...str] is superior to str.split('') because it correctly handles Unicode:

'😎'.split('') // ["�", "�"]
[...'😎'] // ["😎"]

2) What is the difference between slice and splice?

slice copies a range out of an array. splice deletes and/or inserts items at a given position in an array.

3) How to convert an object into a string?

The question's a little to broad imo, I'm gonna spare the time writing out exactly what Avalander did.