DEV Community

Discussion on: 20 Killer JavaScript One Liners ☝️

Collapse
 
webreflection profile image
Andrea Giammarchi

Faster !== Correct ... his string reverse breaks with code points, while [...str] doesn't.

Try it: OP reverse breaks the emoji with reverse('some 💩'); while this reduce suggestion doesn't.

Thread Thread
 
webreflection profile image
Andrea Giammarchi • Edited

P.S.

// this works fast and correct at the same time
const reverse = str => [...str].reverse().join('');
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
eioluseyi profile image
Emmanuel Imolorhe

In a bid to be obnoxious 😏 you could have shortened your code further by 2 characters 🌚

const reverse = str => [...str].reverse().join``;
Enter fullscreen mode Exit fullscreen mode