How to SHUFFLE AN ARRAY in 4 minutes! 🔀

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

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

  • @BroCodez
    @BroCodez  Год назад +2

    // Fisher-Yates algorithm
    const cards = ['A', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K'];
    shuffle(cards);
    console.log(cards);
    function shuffle(array){
    for(let i = array.length - 1; i > 0; i--){
    const random = Math.floor(Math.random() * (i + 1));
    [array[i], array[random]] = [array[random], array[i]];
    }
    }

    • @-_SleepAndEat_-
      @-_SleepAndEat_- 6 месяцев назад

      Bro can you do Kali Linux ?

    • @allangoes2474
      @allangoes2474 5 месяцев назад

      helped me a lot! thanks for the tutorial

  • @AndreaDAuria1
    @AndreaDAuria1 Месяц назад

    Beautiful ❤

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

    oh my god bro this is so helpful! thanks for saving me 25 lines of spaghetti code!

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

    Enjoy the show☺

  • @Gigglesaintlame
    @Gigglesaintlame Год назад +5

    Day 3 ends…. I’ll go check more about reduce()

  • @245B
    @245B 11 месяцев назад +2

    Could you create a tutorial about Rust programming language?

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

    TIP: If (for some reason) you want to make sure that no number ends up in the place it was in before the shuffle, do this minor change in the code.
    ```
    function shuffle(array) {
    for(let i = array.length - 1; i > 0; i--) {
    const random = Math.floor(Math.random() * i); // `i` instead of `i+1`
    [array[i], array[random]] = [array[random], array[i]];
    }
    }
    ```

  • @FatsFalafel
    @FatsFalafel Месяц назад

    How is this more efficient than the first way? Just because of the built in algorithm for the sort() method?

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

    Just a random comment to shuffle the RUclips algorithm🎉

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

    Bro request course lua

  • @educationalbro1611
    @educationalbro1611 11 месяцев назад +2

    bro i am following your previous js playlist should i continue that or should i continue from this series

    • @GarethFlandro
      @GarethFlandro 3 месяца назад

      probably this one is better (but you might be done with both by now lol)

  • @ItsLolwethu
    @ItsLolwethu 11 месяцев назад

    Yes Javascript🃏

  • @yuvrajsingh-fz7hd
    @yuvrajsingh-fz7hd 10 дней назад

    best

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

    What kind of project we use this on?

    • @professorpoke
      @professorpoke Месяц назад

      May be some card game, or anything where you need to shuffle an array to create a different/random scenario everytime.

  • @90XANAS
    @90XANAS 11 месяцев назад

    bro please elaborate a lil bit more of JS topics...

  • @tomiczdarko
    @tomiczdarko 8 месяцев назад +1

    What a stupid language. But explanation is good.

  • @KeskilChnProgram
    @KeskilChnProgram 11 месяцев назад

    Bro, how many topics about JS left?