How to randomly sort an array? | LeetCode task | JavaScript

Опубликовано: 04 October 2026
на канале: Front-end Science with Sergey Puzankov
12,997
759

Hello, friends! Today we have a medium-sized LeetCode problem called "Shuffle Array." This is a very popular problem; I personally encountered it in an interview about six years ago.

This problem is also very practical and often in demand in front-end development. For example, you need to create an audio player and want to be able to randomly sort a playlist of songs. That's exactly what our algorithm for today will do.

We'll look at two approaches to solving this problem. We'll discuss a straightforward approach and also examine the Fisher-Yates algorithm. And, of course, we'll discuss the time and memory complexity of these algorithms.

Enjoy!

Link to the code from the video: https://codepen.io/puzankov/pen/abBOZ...
Link to the problem on Leetcode: https://leetcode.com/problems/shuffle...

Video about rounding numbers:    • Методы округления чисел в JS: Math.round, ...  

Be sure to share your solutions in the comments below! Like and share this video with your friends!
---
If you found this video helpful, please like and share it with your friends.
Subscribe to our channel: http://bit.ly/fs-ytb
---

Follow us on social media:
FB:   / frontendscience  
Sergey Puzankov's Instagram:   / puzankovcom  

Visit our website: http://frontend-science.com/

Music by Blue Wednesday - Suede

#leetcode #javascript #JStasks #itinterview