How do I reverse an array in JavaScript in 16 characters or less without .reverse()?

落花浮王杯 提交于 2019-12-02 13:23:41

I'd like to give you a hint, without giving you the answer:

You're close, but you can save characters by not using something you need to add in your code.

By adding the thing you won't use, you can remove ().


Spoiler (answer):

// Note: this only really works for this specific case.
// Never EVER use this in a real-life scenario.

var a = [1,2,3,'a','b','c',[]]

weirdReverse=a=>a.sort(x=>1)
//                     ^ That's 1 character shorter than ()

console.log(weirdReverse(a))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!