JavaScript Array Sort Method Practice in 5 Minutes

Поділитися
Вставка
  • Опубліковано 5 лют 2025

КОМЕНТАРІ • 55

  • @aaronlinton-chambers
    @aaronlinton-chambers 4 роки тому +12

    This is by far my favourite coding channel on UA-cam. Clear concise instructions and a worksheet to engage with. Thanks James have an amazing Thursday.

    • @JamesQQuick
      @JamesQQuick  4 роки тому +2

      Wow that’s like the best compliment I’ve ever gotten! :)

  • @nicholaskozlarek3169
    @nicholaskozlarek3169 2 роки тому +3

    This repository was amazing. I am starting a coding bootcamp in a few days and brushing up on this makes me feel WAAAAY more confident. Thanks!

  • @bradpeters9511
    @bradpeters9511 2 роки тому +1

    Very easy to understand. Thank you for doing examples with numbers and strings.

  • @gbbowler
    @gbbowler 4 роки тому +3

    James, these are great short vids. I love doing the short exercises.

    • @JamesQQuick
      @JamesQQuick  4 роки тому

      Glad you’re enjoying it. Any other topics you’d like to see?

  • @exodion4173
    @exodion4173 2 роки тому

    I loved that there were different types of examples. Thank you

  • @PFOctavio
    @PFOctavio 3 роки тому +1

    All this videos have helped me so much, i really appreciate them

  • @zacwilson8009
    @zacwilson8009 4 роки тому

    I love how you have the repo for these lessons. Keep it up man you're killing it

  • @KieCodes
    @KieCodes 4 роки тому +2

    Again an amazing value packed video! Thank you!

  • @mihirrawat3074
    @mihirrawat3074 4 роки тому +1

    Keep doing what u do, great mann!

  • @elie8181
    @elie8181 3 роки тому

    Hello James, thanks and very good job, from France !

  • @luciamelgarejo2953
    @luciamelgarejo2953 2 роки тому

    Thank you. You teach amazing!.

  • @mariapaderina5992
    @mariapaderina5992 4 роки тому

    Thank you James! Very cool and understandable tutorials ! I got the idea of array` s methods only from your videos!

  • @indian_gagan
    @indian_gagan 4 роки тому

    Wow...Javascript series ❤❤
    Really excited for this series

    • @JamesQQuick
      @JamesQQuick  4 роки тому

      Hope you’re enjoying it so far!

    • @indian_gagan
      @indian_gagan 4 роки тому

      @@JamesQQuick you are someone who is helping young developers a lot....big thanks to you...im currently learning frontend web development and its so amazing and your videos are huge support for us.
      Thankyou so much James ❤😀

    • @JamesQQuick
      @JamesQQuick  4 роки тому +1

      @@indian_gagan This means a lot! :) Thank you!!

  • @stefanzander5956
    @stefanzander5956 4 роки тому

    Didactically very well produced and presented. Great Work!

  • @TheMugen18
    @TheMugen18 3 роки тому

    Thank you James! Very cool and understandable tutorials !

  • @anahitharutyunyan3066
    @anahitharutyunyan3066 2 роки тому

    Thank you for great explanation.

  • @jazper808
    @jazper808 3 роки тому

    thank you James for sharing knowledge.

  • @fenrirbr
    @fenrirbr 4 роки тому +4

    small suggestion, you could've used a console.clear() at the start of the file so following the console would be a little clearer

  • @FPLogistic
    @FPLogistic 3 роки тому

    I finally understand it, thank you!

  • @panoptech769
    @panoptech769 2 роки тому

    what are you saying you are running at 2:25? Did you say node mod? trying to get that extension but cant find it

    • @Hacking-NASSA-with-HTML
      @Hacking-NASSA-with-HTML 2 роки тому

      I believe it's a Nodemon, live updating your js file; something like "live server" extension for VSCode editor which works with html files (I use it)

    • @Hacking-NASSA-with-HTML
      @Hacking-NASSA-with-HTML 2 роки тому

      I mean you just create a blank index HTML file, put a script file inside HTML, and start live server. Works perfectly.

  • @doniaelfouly4142
    @doniaelfouly4142 Рік тому

    Thanks

  • @arjmli
    @arjmli 2 роки тому

    Thank you

  • @mohamedyoussef8835
    @mohamedyoussef8835 3 роки тому

    Excellent

  • @Singlerity
    @Singlerity 2 роки тому +1

    New to coding here. I don't understand how sort by name works. How does the conditional understand that Anakin is alphabetically smaller than Darth? Do the strings have hidden alphabetical values?

    • @JamesQQuick
      @JamesQQuick  2 роки тому

      Great question. They have hidden mathematical values actually. Each character has a number code behind it so they can be sorted mathematically.

    • @vladrileynavilys
      @vladrileynavilys 2 роки тому +1

      @@JamesQQuick "character" being, in this case the letters forming each character's name!

  • @jeka2233
    @jeka2233 3 роки тому

    So helpful

  • @maxlong1374
    @maxlong1374 2 роки тому

    Better than GOT for an eager heart to learn

  • @Danskermemes03
    @Danskermemes03 2 роки тому

    how do i get the terminal to work

  • @Alphadec
    @Alphadec 4 роки тому

    how do u display each object in a card. ?

  • @reanibutani9555
    @reanibutani9555 4 роки тому +1

    I want to be great at javascript :)

  • @mithunshaw4269
    @mithunshaw4269 2 роки тому

    how to sort each words in an array like was would be aws, and would be adn and so on...
    first we sort entire array and then how do we sort each words and print them like below
    //input
    let str = 'ram ramesh sahil harsh abhay ali gopi'
    // output -> 'aabhy aehmrs ahhrs ahils ail amr giop'

  • @mapkbalaji
    @mapkbalaji 4 роки тому

    What to do if we need to sort by gender and name?

    • @vmag77
      @vmag77 4 роки тому

      This is how i did it, but i'm sure there is probably a better way.
      const byGender = characters.sort((a, b) => {
      if (a.gender < b.gender) return -1;
      if (a.gender > b.gender) return 1;
      if (a.name < b.name) return -1;
      if (a.name > b.name) return 1;
      });
      console.log('----- Sorted by Gender -----');
      console.log(byGender);

    • @soniablanche5672
      @soniablanche5672 4 роки тому

      Assuming you want to create a general comparator function, you can do something like this. Keep in mind that it will compare the properties directly so you'd have to modify the logic of comparison to suit your needs:
      function comparator(...properties) {
      return function(a,b) {
      const property = properties[0];
      if(a[property] > b[property]) return -1;
      if(a[property] < b[property]) return 1;
      if(properties.length > 1) return comparator(...properties.slice(1))(a,b);
      return 0;
      }
      }
      characters.sort(comparator("gender","name"));
      this should sort by gender, and if gender is equal then it will compare the names. You can keep adding parameters to the comparator function if you want to sort by even more properties.

    • @TomS-rv8me
      @TomS-rv8me 3 роки тому

      This also works:
      const sortGenderName = characters.sort((a,b) => `${a.gender}${a.name}` > `${b.gender}${b.name}` ? 1 : -1);
      console.log(sortGenderName);
      For anything more complicated, the function approach described above would probably be better.

  • @micemincer
    @micemincer 3 роки тому +1

    isn't anakin and darth vader the same character?

  • @soniablanche5672
    @soniablanche5672 4 роки тому +1

    btw .sort() does not return a new array, it returns the original for convenience.

  • @Ashish_singh_dev
    @Ashish_singh_dev 3 роки тому +1

    those who are looking for james's github page which he might forgot to put in his video's description
    data page link :- github.com/jamesqquick/javascript-array-functions-practice

  • @kennyPAGC
    @kennyPAGC 4 роки тому

    You need to return 0 when the sort value is the same. I guess returning nothing works the same way (undefined), but the docs are explicit about returnin 0, so that's how it should be done if you want to do it "properly".

    • @JamesQQuick
      @JamesQQuick  4 роки тому

      Fair enough. Ya it doesn’t really matter what you return but always good to reference the docs.

    • @soniablanche5672
      @soniablanche5672 4 роки тому

      In his examples, he either returning 1 or -1. He never returned undefined.

  • @jonathansigg8563
    @jonathansigg8563 4 роки тому +4

    instead of doing return twice, you should better use this ------> const byName = characters.sort((a, b) => a.name < b.name ? -1 : 1);

  • @vikrantshah1633
    @vikrantshah1633 2 роки тому

    What about Dates it’s confusing

  • @thomasersosi4595
    @thomasersosi4595 4 роки тому

    Take a look at developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare for sorting strings.

  • @DastageerHC
    @DastageerHC 3 роки тому +3

    you did everything except explaining how the sort method works