How sort works in JavaScript

  Рет қаралды 3,260

CJ Avilla

CJ Avilla

Күн бұрын

Learn why sorting a list of numbers in javascript yields unexpected results and how to use a compare function. Also, we'll show how the sort function on the Array.prototype might be implemented by re-implementing it our own `Array.prototype.mySort` that accepts our own compare function.
00:00 sort basics
02:00 Implement mySort with the merge sort algorithm
Code
gist.github.com/cjavdev/9fbfc...

Пікірлер: 15
@alejandrogomezanaya6306
@alejandrogomezanaya6306 6 ай бұрын
Thanks for you explanation! It's very clear and specific.
@anandhapriya5430
@anandhapriya5430 11 ай бұрын
Wow! beautifully explained. 👌
@mbbvines1848
@mbbvines1848 2 жыл бұрын
really informative video. it shows the Internal working also. thanks a lot
@Angkush-ry3oc
@Angkush-ry3oc 2 жыл бұрын
It was really helpful 🙏
@davisnoah347
@davisnoah347 2 жыл бұрын
Love the detail and care you put into this video. Truly remarkable. You ought to get more views.
@davisnoah347
@davisnoah347 2 жыл бұрын
This video isn't just nice. It's frickin awesome. I love the way you explain it in simple terms. Not even fiinished watching yet. Ya earned a subscriber here. Keep up the good work.
@jsuryakt
@jsuryakt Жыл бұрын
Beautifully explained. Thank you for this
@alirezafereydoni2827
@alirezafereydoni2827 2 жыл бұрын
That's awesome
@leonardorusso6419
@leonardorusso6419 2 жыл бұрын
Nice video, thank you! P.s how you got that window for live run of the script ?
@cjav_dev
@cjav_dev 2 жыл бұрын
I’m using split panes in the terminal I use called iTerm.
@leonardorusso6419
@leonardorusso6419 2 жыл бұрын
@@cjav_dev Thanks!!
@totfosk
@totfosk Жыл бұрын
Hi ! Is it possible to know what does the sorting function do exactly? It does check if the sum or subtraction of a and b is positive or negative, but if you put for instance 4 values... what the hell is running underneath? I made console.log of 'a' having an array of 4 values and the console shows: on the first line the second value, then 3 lines of the third value and then 2 lines of the forth. 'b' shows: on the first line, the first value, then 2 lines of the second, then 2 lines of the first value again, and last line, the third. I am wondering how can an argument represent so many lines and what is going on... A method is just code that we don't see right? I am very new. Cheers!
@soniablanche5672
@soniablanche5672 Жыл бұрын
every javascript engine will implement sort in a different way but you can more or less assume they are using quicksort
@totfosk
@totfosk Жыл бұрын
@@soniablanche5672 gracias Sonia !!!
@soniablanche5672
@soniablanche5672 Жыл бұрын
original sort returns the original array itself because it mutates the array
Transistor.fm API fetch from 11ty
13:05
CJ Avilla
Рет қаралды 399
JavaScript Comparator Function | Sorting Explained!
12:21
The Code Creative
Рет қаралды 32 М.
ЧУТЬ НЕ УТОНУЛ #shorts
00:27
Паша Осадчий
Рет қаралды 10 МЛН
Red❤️+Green💚=
00:38
ISSEI / いっせい
Рет қаралды 89 МЛН
but what is 'a lifetime?
12:20
leddoo
Рет қаралды 65 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 778 М.
SHA: Secure Hashing Algorithm - Computerphile
10:21
Computerphile
Рет қаралды 1,2 МЛН
Learn JavaScript SORTING in 6 minutes! 🗃
6:42
Bro Code
Рет қаралды 19 М.
Why javascript sort gets so many memes
8:22
Hitesh Choudhary
Рет қаралды 21 М.
JavaScript Array Sort Method Practice in 5 Minutes
7:13
James Q Quick
Рет қаралды 35 М.
Sort Numbers in JavaScript
8:24
Stefan Rows
Рет қаралды 829
What is a Monad? - Computerphile
21:50
Computerphile
Рет қаралды 598 М.
JavaScript Array Reduce
7:42
Programming with Mosh
Рет қаралды 335 М.
Forming of goal foam || A2Z SKLLS
1:00
A2Z SKILLS
Рет қаралды 39 МЛН
Nutella-Kinder burrito bomb ! 🤤🎉
0:47
adrian ghervan
Рет қаралды 12 МЛН
Epic Beach Day! Digging a Massive Hole!
0:12
MELIAH & DAD (THE PONTES FAMILY)
Рет қаралды 6 МЛН
How Can parents love their children equally? #shorts
0:38
mountainlion5
Рет қаралды 11 МЛН