CodeRecipe: How to reverse an array in JavaScript

Samantha Ming on August 19, 2019

Here's a Code Recipe to keep around if you need to reverse the order of the elements of an array. You can use the array method, "reverse()" โช T... [Read Full]
markdown guide

Lol, itโ€™s a good name! Hopefully itโ€™s just Benjamin and not Benjamin button ๐Ÿ˜‚


Phew! Cause I donโ€™t think I know a doctor for that otherwise ๐Ÿ˜‚


Hey Samantha,

I have a question: What is the runtime of Array.reverse() method ?

Thank you ๐Ÿ˜Š


Thank you Samantha, I think if you text the best way fpr the performance, it will be a great article.


I decided to test another way of thinking this. Here are the results:

with slice and reverse: 83.085ms
With one loop: 309.763ms

Source-code and tests are available here.

I though that using one for loop (compared to a chained call using slice & reverse) would be more performant. I was wrong.

What Samantha showed is great work, I'm trying to show alternatives and another way of thinking this through.


Fantastic! Thanks for sharing this! Iโ€™ll add this to my notes ๐Ÿ‘๐Ÿ‘๐Ÿ‘


Youโ€™re right I should of done test ๐Ÿ˜…

If someone is reading this and youโ€™ve done test. Drop it in the comments and Iโ€™ll add it to my code notes! ๐Ÿ’ฏ

code of conduct - report abuse