JavaScript Comparator Function | Sorting Explained!

Поделиться
HTML-код
  • Опубликовано: 10 сен 2024
  • НаукаНаука

Комментарии • 317

  • @TheCodeCreative
    @TheCodeCreative  2 года назад +1

    🎓 New Course Available! "Scrollytelling 101": store.thecodecreative.com/scrollytelling

  • @romanmontoya5950
    @romanmontoya5950 3 года назад +36

    not only did I fully learn and understand the logic behind the comparator function, but I also found myself starting to relax and peacefully enjoy learning it just by the cadence and tone of your voice. Thank you! Just subscribed

  • @mondirhallouli
    @mondirhallouli 3 года назад +21

    really hits the spot in my ADHD brain! glad I found this video. now I understand the comparator function much better!

    • @TheCodeCreative
      @TheCodeCreative  3 года назад +1

      That's great to hear Mondir. 👍🏻 Thanks for watching!

    • @Nightizm
      @Nightizm 2 года назад

      couldn't' agree more!

  • @teenytinytoons
    @teenytinytoons 3 года назад +4

    holy smokes. the most thorough video on a comparator function ever. this made it really click for me. amazing walk-through and explanation.

  • @numanakhtersiddiqui6573
    @numanakhtersiddiqui6573 3 года назад +21

    finally someone explained this in such an easy manner.💕

  • @23Kattayopp
    @23Kattayopp Год назад +2

    you have no idea how much content i've watched until finding this video that made everything so clear for me! thanks a lot, Gregg!

  • @kerisek11
    @kerisek11 Год назад +3

    I have 4 best-rating courses on Udemy, but this teacher is THE BEST.

  • @ChabPoha
    @ChabPoha 5 месяцев назад +1

    underrated ytber , only vid on yt who perfectly explains the sorting method hats off bro ,

  • @e-prog9968
    @e-prog9968 8 месяцев назад +1

    Amazing! Showing the reason why it is sorting the way it sorting was the best part!
    Thank you!

  • @MrRameez420
    @MrRameez420 Год назад +1

    why this video has so few views? he literally explained it in a way I'll never forget my entire life!

  • @rich4363
    @rich4363 3 года назад +2

    i love how thorough you were. i watched it twice and now i can see so many ways that this will be useful.

  • @locle9389
    @locle9389 3 года назад +3

    Thank You So Much. I've been flipping through hours of videos and documentations but still struggle to understand what the comparator function do. Your video definitely makes things clearer especially when you wrote out the if statements and have them return -1, 1, and 0. Everything just clicked.

  • @omarvayani3452
    @omarvayani3452 2 года назад +1

    for a channel that teaches this well it deserves more subs👍

  • @ravanabuddha3955
    @ravanabuddha3955 Год назад +1

    I was stuck with the problem of writing a custom sort for my nested array and when I found the MDN docs for the topic I couldn't understand the logic behind returning 1, -1 & 0. But sir you explained so well and really saved me & made my day, I can't thank you enough.

  • @syedzidane940
    @syedzidane940 Год назад +1

    I finally understood the sort method and comparator function but what I don't understand is how come this guy only has around 8K subscribers!?? Given the quality of the content, imo he should have atleast half a million subs

  • @farazk9729
    @farazk9729 3 года назад +2

    Thank you so much.
    a) Very organized explanation and easy to understand.
    b) Soothing voice in the midst of this confusion called learning.
    c) Liked and subscribed.
    Thanks again,

  • @arinzeodukwe2862
    @arinzeodukwe2862 Год назад +1

    Finally, I understood the logic behind this "compareFunction" callback function. Thanks a lot.

  • @atmsudawa6925
    @atmsudawa6925 2 года назад +1

    Wow!!! finally i understand this sorting topic in an easier way. The analogy in this video will help even a slow learners thanks

  • @65189sumon
    @65189sumon 3 года назад +1

    Finally I understand Array Sorting. Thank you very much

  • @andresfelipeladinoespitia
    @andresfelipeladinoespitia Год назад +1

    Thanks my man! I'd been searching for a clear, straightforward, and hands-on explanation to no avail. That's until I got to your video. Great work!

  • @TheCodeCreative
    @TheCodeCreative  4 года назад +3

    To subscribe to the channel: ruclips.net/channel/UCmOpHGj4JRWCdXhllVTZCVw

  • @thecodelife9855
    @thecodelife9855 Год назад +1

    thank you for explaining this in depth. Other people were just repeating what was written in w3schools website.

  • @victoriapanidi1419
    @victoriapanidi1419 3 месяца назад +1

    Thank you so much!!! This is one of the best explanation videos that I ever have seen about this topic.

  • @stgermanrobert
    @stgermanrobert Год назад +1

    Thanks to this video I could do exercise number 8 of Jonas Schmedtmann's coding challenge about array methods! Thank you so much, nice voice btw!

  • @tenzinwoeser6842
    @tenzinwoeser6842 Год назад +1

    Really clear explanation. Love how you explain return logic and the charCodeAt logic. Thanks

  • @viveknepal8959
    @viveknepal8959 Год назад +1

    I was so confused before, thank you so much to explain this in such a simple and easier way.

  • @TheCodeCreative
    @TheCodeCreative  2 года назад

    Join "The Code Creative Community" group on Facebook: facebook.com/groups/thecodecreative

  • @leviciarrocchi7895
    @leviciarrocchi7895 3 года назад +3

    Wow! This video is amazing. I was trying to understand this function and how it works, and with your tips now I understood! Thankyou

    • @TheCodeCreative
      @TheCodeCreative  3 года назад +1

      Glad it was helpful to you Levi. Thanks for watching!

  • @2010chalupa
    @2010chalupa 3 года назад +2

    I wanted to thank you for the video, I could understand better the a-b logic, and I also had some fun while learning. Keep posting videos like this, means a lot for some of us, even when English is not our first language, we learn a lot.Thanks again.

  • @lycan2494
    @lycan2494 2 года назад +2

    the only good video on basic sort so far

  • @mayankverma4638
    @mayankverma4638 Год назад +1

    Hands down the best explanation, Thank you very much!

  • @robinsajwan5976
    @robinsajwan5976 2 года назад +1

    Sir, your way of explaining is too good, 💎

  • @ghokuos89
    @ghokuos89 Год назад +1

    Im pretty sure you could teach an Ant to become an austronaut, but for real, i wasn't understanding it clearly but you made it simple for me, thank you!

  • @matt112fly
    @matt112fly Месяц назад +1

    i wasnt sure how the -1 and 0 and 1 affect the returned result.. thanks for claryfing things up !

  • @samuelpalacios9661
    @samuelpalacios9661 2 года назад +1

    Finally! What a clear explanation, thank u!! I would love if you make a video explaining what return is :)

    • @TheCodeCreative
      @TheCodeCreative  2 года назад +1

      Do you mean "return" as in a return statement within a function?

    • @samuelpalacios9661
      @samuelpalacios9661 2 года назад

      @@TheCodeCreative Yup, return statement within a function

  • @TheCodeCreative
    @TheCodeCreative  2 года назад

    📖 Download my FREE "Google Search Secrets for Developers" Cheat Sheet:
    store.thecodecreative.com/google-secrets-cheat-sheet

  • @thydevdom
    @thydevdom 3 года назад +1

    I think I finally found the perfect pace and instructor….

  • @sebastianrodelo7965
    @sebastianrodelo7965 3 года назад +1

    Thanks!!, this was breaking my head. Greetings from Colombia.

  • @mohammadhosseinjahanbakhsh2159
    @mohammadhosseinjahanbakhsh2159 3 года назад +1

    thank u! your channel is underrated

  • @shawnmichaelalberto7519
    @shawnmichaelalberto7519 2 года назад +1

    Explained it a lot clearer than other tutorials. You just earned another subscriber!

  • @princesamuel8956
    @princesamuel8956 3 года назад +1

    i encourage you to do more tutorial , i never have i ever commented on some tutorial videos this was the first one the way that you explain is was so good ,keep doing it

  • @Hamza__Sardar_Khan
    @Hamza__Sardar_Khan 2 месяца назад +2

    Literally Perfect ! Just Perfect ! 😘

  • @girveriusmcfarland5716
    @girveriusmcfarland5716 2 года назад +1

    Sir you are God sent! Thank you so much! It make perfect sense now.

  • @btssugahit4663
    @btssugahit4663 Год назад

    Bro you deserve million of subscribers. I watched a lot of videos before i finally found this masterpiece. Thank you so much it really helped a lot. Hope our professors would teach the way you do.

    • @TheCodeCreative
      @TheCodeCreative  Год назад

      Thank you so much 😀 It's encouraging to know that the videos are helpful. 👍🏻

  • @dapolcio3405
    @dapolcio3405 2 года назад +1

    The best explanation ever.

  • @okaybossiamonyoutubeakkskd
    @okaybossiamonyoutubeakkskd 2 года назад +1

    thank you sir for the beautiful explanation. You really deserve a lot more subs

  • @thedevguild7525
    @thedevguild7525 2 года назад +1

    Wow you are very good! Probably the best in explaining the comparator function.
    So far, you might be the only one who show the respective utf code, and also be comprehensive enough to show for alphabets and numbers.
    Liked plus Subscribed!

    • @TheCodeCreative
      @TheCodeCreative  2 года назад

      Great, thank you! Glad it was helpful 👍🏻

  • @itsreason3238
    @itsreason3238 Год назад +1

    Thank you. I like to learn how and why something is the way it is. I intend to reverse engineer the sort method myself to fully understand and appreciate the method. I think I can do it by using nested for loops and conditional logic.

  • @abdurahmanargoebie3149
    @abdurahmanargoebie3149 2 года назад +1

    Thanks for your explanation make me understand about sort function javascript👍

    • @TheCodeCreative
      @TheCodeCreative  2 года назад

      Excellent! Any other topics you'd like to see a video on?

  • @abhigyansarmah716
    @abhigyansarmah716 2 года назад +1

    That was just too good. Thank you so much for such a lucid explanation. Keep contributing your knowledge. There are very few people out there who can teach concepts in such detail.

    • @TheCodeCreative
      @TheCodeCreative  2 года назад

      Great, thanks! Glad it was helpful!

    • @abhigyansarmah716
      @abhigyansarmah716 2 года назад

      @@TheCodeCreative It was indeed very helpful. Thanks again.

  • @mitchtembo487
    @mitchtembo487 3 года назад +2

    Thank you for this video . Just loved how you thoroughly explained everything . looking forward to learning more topics with you

    • @TheCodeCreative
      @TheCodeCreative  3 года назад

      Hey Mitch! Thanks for the comment. More videos coming soon 👍🏻

  • @themissingavett
    @themissingavett 2 года назад +1

    Thanks! you explained this so clearly and thoroughly. Well done good sir.

  • @user-ef5gt8so8b
    @user-ef5gt8so8b 2 года назад +1

    Thank you so much for your excellent explanation. Now I really do understand the logic behind those dubious comparator functions after having read it in a book. Great video! I subscribed right away

  • @compean7360
    @compean7360 3 года назад +1

    Finally I could understand, thanks!

  • @mardokahvejian4847
    @mardokahvejian4847 2 года назад +1

    you are the best explainer thank you so much

  • @codebykeoma
    @codebykeoma 2 года назад +1

    Great video! I am clearer on this topic now.

  • @sagarsuryawanshi8735
    @sagarsuryawanshi8735 3 года назад +2

    Superb explanation , with meaningful insights!!!

  • @alexlions8633
    @alexlions8633 Год назад +1

    great explanation that I have ever seen, thank you

  • @tomasgilamoedo8301
    @tomasgilamoedo8301 3 года назад +1

    Spectacular explanation! really appreciate it, thxz man

  • @georgeem9954
    @georgeem9954 2 года назад +1

    Clearly explained.Thank you

    • @TheCodeCreative
      @TheCodeCreative  2 года назад

      Glad it helped! Feel free to join the Facebook group: facebook.com/groups/thecodecreative

  • @SamShiFitness
    @SamShiFitness 3 года назад +1

    Woow Thank Budy !!! Finally i understand a-b or b-a
    Thank You So Much Brother
    Keep It Up

    • @TheCodeCreative
      @TheCodeCreative  3 года назад +1

      That's great to hear, thanks for watching!

  • @_tanzil_
    @_tanzil_ Год назад +1

    Wow! You made that easy to understand for me. SUBSCRIBED

  • @mightydudegrafuroam8424
    @mightydudegrafuroam8424 2 года назад +1

    Simple and concise. Thanks for the vid man!

  • @fullStackInKannada
    @fullStackInKannada 2 года назад +1

    Very nice explanatory, thank you so much for that.

  • @edwinly9865
    @edwinly9865 2 года назад +1

    Seriously well explained! !

  • @gemrwx
    @gemrwx Год назад +1

    The first iteration a is going to take the value of the second item in the array and b is going to take the first item of the array.
    [5, 2]
    comparatorFunction(a, b) // a = 2 and b = 5

    • @Thikondrius
      @Thikondrius 10 месяцев назад

      I see indeed, do you know why ?

  • @sumaganjal
    @sumaganjal 2 года назад +1

    Thank you, finally understood

  • @subhashgn1775
    @subhashgn1775 2 года назад +1

    Thank you.
    Very well explained.

  • @muneebnawaz1392
    @muneebnawaz1392 3 года назад +1

    Thanks.. you just explained it in simplest way💖

  • @deus3404
    @deus3404 2 года назад +1

    THANK YOU! Keep up the good work!

  • @AlphaWatt
    @AlphaWatt 2 года назад +1

    This is great. Thank you very much!

  • @FourDollarBill
    @FourDollarBill 2 года назад +1

    Exactly what I was looking for. Thank you!

  • @Kiarash7042
    @Kiarash7042 2 года назад +1

    thank you very much you explained it very well

  • @ShopperPlug
    @ShopperPlug 2 года назад +1

    Excellent explanation.

  • @btw_alya
    @btw_alya Год назад +1

    really really thanks a lot🙏🙏 this makes all clear for me about sort method
    thanks to you🙏
    i really appreciate your efforts sir🙏 thank you so much
    this is really appreciable🌸✨ thank you once again for saving me✨

  • @draganbogdan4267
    @draganbogdan4267 2 года назад +1

    Great teacher!

  • @neo90sr
    @neo90sr 3 года назад +1

    Just what I was looking for, very clear explanation. Thanks 👍

  • @ShubhamPal-yi9kp
    @ShubhamPal-yi9kp Год назад +1

    thanks for the teaching

  • @aravindm6124
    @aravindm6124 2 года назад +1

    fantastic explanation !!!! , Thanks much!!!😀

  • @0xR3Ze
    @0xR3Ze 3 года назад +1

    Thank You, I hope you get more views Sir!.

  • @VanVlearMusic
    @VanVlearMusic 6 месяцев назад +1

    This was great, thank you!!

  • @josephisaac6664
    @josephisaac6664 7 месяцев назад

    a tiny correction, in the comparator function, the first argument(a) is actually the second value of a pair of adjacent values being compared.
    So in the case of [2, 5, 100, 4], on the first iteration, a is 5 and b is 2. It's a little counter intuitive but in that case, a < b means 5 < 2. If true, we return a negative number, which means a should be before b, that is 5 should be before 2. (This is false)
    Else if a > b i.e., 5 > 2, we return positive number, which means b should be before a, that is 2 should be before 5. (This is true)

  • @user-hz4dz9fl4n
    @user-hz4dz9fl4n 6 месяцев назад +1

    Thank you, It was really useful

  • @andromilk2634
    @andromilk2634 7 месяцев назад

    Hi, thanks for the very clear explanation, it's the first video I see which explains it in depth to this extent. There's just something which I was wondering about the comparator function : how exactly does it do the comparison between the different elements in the array? What exactly is happening behind the scenes? Some special kind of algorithm is implemented to compare the elements in a certain order? (is the first element compared to all the other elements of the array, then the second to all the others until the end, etc. or something else?) Hopefully my question makes sense.

  • @rameenana
    @rameenana Год назад +1

    Thanks man. This was helpful.

  • @pranabroy8218
    @pranabroy8218 3 года назад +1

    Very well explained.

  • @mirelahi2291
    @mirelahi2291 2 года назад +1

    such a good content! Keep up the good work. Thanks.

  • @amedeocalzolai156
    @amedeocalzolai156 2 года назад +1

    Great explanation thanks 🙏

  • @StrangerDanger352
    @StrangerDanger352 Год назад +1

    Loved it you teaching so good Thank you :)

  • @FiveFourThor
    @FiveFourThor 2 года назад +1

    amazing tutorial!! 😁

  • @mohamedalaa6199
    @mohamedalaa6199 2 года назад +1

    THANK YOU FROM MY HEART

  • @shubhamh7451
    @shubhamh7451 3 года назад +1

    Thank you so much, pretty clear explaination! subbed

  • @SumoLife
    @SumoLife 3 года назад +1

    Superb explanation!

  • @Arttyor
    @Arttyor 2 года назад +1

    if I have 2 numbers in array [ 2, 5]
    And I use .sort(...) with comparable fn, and I just console log a and b....5 will show as a, and 2 as b....why is that?

  • @akshaydeogaonkar7120
    @akshaydeogaonkar7120 11 месяцев назад +1

    When it was at 09:35 I instantly subscribed! 🤣🤣🤣😇😇

  • @noorb374
    @noorb374 Год назад +1

    superb .. thankyou for this

  • @user-sg6yq9ez6u
    @user-sg6yq9ez6u Год назад +1

    What I don' t understand is how the values are taken after the first operation?
    For example , in the video , in the first step a is 2 and b is 5 so 2 is sorted before 5. However, after that which value is taken as a and b? Is it 2 and 100 or 5 and 100? I am confused. Can someone please explain the step wise process of this sort operation?

  • @penguinxed
    @penguinxed 2 года назад +1

    well explained sir, thank you :)

  • @royscult9
    @royscult9 Год назад +1

    Thank you so much for this

  • @carlojuanchofuntanilla
    @carlojuanchofuntanilla Год назад +1

    wow thank you well explained