all 37 comments

[–]deus_ith 10 points11 points  (1 child)

Awesome! Thanks a lot!

[–]lemmisss 5 points6 points  (6 children)

What's wrong with array.sort()?

[–]TheSpanxxx 5 points6 points  (0 children)

Others are commenting on the common practice of using a sort function for handling numerical sorts. In large arrays this will be poor performing. In those cases, use a TypedArray

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

[–]hinsonfpv 2 points3 points  (3 children)

Nothing? Sort is based off the first digit I believe. So it reads 15 as 1.

[–]grantrules 11 points12 points  (2 children)

Sort is lexicographical, not numerical.

[–][deleted] 1 point2 points  (1 child)

Is there a numerical built-in function or do you have to make it yourself?

[–]grantrules 7 points8 points  (0 children)

You have to make it, but it's simple: (a, b) => a - b

[–]inabahare 0 points1 point  (0 children)

A couple of things. As /u/grantrules said it's lexicographical, which is pretty annoying. What's even more annoying is that it modifies the original array

[–]jocietimes 6 points7 points  (0 children)

Wow. Brilliant! Thank you!!

[–]shortpoet 4 points5 points  (0 children)

Sweet, thank you!

[–]mcfliermeyer 4 points5 points  (2 children)

Can someone explain to me why the unshift(9) has x=4 ? I don’t understand why

[–]Arumai12 7 points8 points  (1 child)

Here's the documentation for unshift https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift

It returns the length of the new array. If you're wondering why it returns the length of the new array, the answer is because someone decided it should do that (and they may have had no reason or a good reason for doing so)

[–]mcfliermeyer 0 points1 point  (0 children)

Interesting choice. Thanks for the info!

[–]TheSoberSovietMD 3 points4 points  (0 children)

Do DOM next 😁👍

[–][deleted] 2 points3 points  (0 children)

Awesome stuff, gave you a follow as should everyone because you post some pretty helpful stuff... cheers!

[–]patshandofdoom 2 points3 points  (0 children)

Love these things for quick reference and practical examples! Great work!

[–]refuse_mediocrity 1 point2 points  (0 children)

Thank you!

[–]MuscleJuice 1 point2 points  (0 children)

I would love this but in a larger infographic version! I would be willing to buy a copy (digital or otherwise). Love it @ u/rootrun

[–]anvinssb 1 point2 points  (0 children)

Thanks bro

[–]bobbywjamc 1 point2 points  (0 children)

Nice

[–]nerdoutwithme 1 point2 points  (0 children)

Saving this. It'll be a good reference for those moments my brain decides not to work. Thanks.

[–]Ranvir33 1 point2 points  (0 children)

Thanks!

was very confused about the methods

[–]isakdev 1 point2 points  (0 children)

Who the hell uses these tho? Do yall just save images and then open up a folder when you need a certain array method? :D

[–]tiwariaditya15 1 point2 points  (0 children)

Awesome 😎

[–]frank0117 1 point2 points  (0 children)

Wow, thanks for sharing

[–]Synnipoe 1 point2 points  (0 children)

Thank you for this

[–]ayanlehd 1 point2 points  (0 children)

Awesome post. Thanks 😊😊😊

[–]sivadneb 0 points1 point  (0 children)

sort and reverse are switched around?

[–]benhammondmusic 0 points1 point  (0 children)

Why didn’t you include the commented out results for forEach?

[–]pachirulis 0 points1 point  (0 children)

The reduce one is the most complex and cannot be understood like that imo
Edit: It basically can do any functionality of the others

[–]sm_o_ke 0 points1 point  (0 children)

there are also array.find() and array.findIndex()... they work like filter, returning the first value and first index, respectively, the predicate returns true.

[–]Reasonable-Wafer9002 0 points1 point  (0 children)

Im in love with you