

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is it correct to use JavaScript Array.sort() method for shuffling?
Yes, you can use the JavaScript Array.sort() method for shuffling. Let’s see how
Example
function shuffleDisplay(arr) { var tmp, current; // calculating length var top = arr.length; if(top) while(--top) { current = Math.floor(Math.random() * (top + 1)); tmp = arr[current]; arr[current] = arr[top]; arr[top] = tmp; } return arr; }
- Related Questions & Answers
- C++ Program to Implement Fisher-Yates Algorithm for Array Shuffling
- Use array as sort order in JavaScript
- Randomly shuffling an array of literals in JavaScript
- Shuffling string based on an array in JavaScript
- JavaScript Sort() method
- How to use the Sort() method of array class in C#?
- Check if it is possible to sort the array after rotating it in Python
- JavaScript Bubble sort for objects in an array
- Which algorithm does the JavaScript Array#sort() function use?
- How to use std::sort to sort an array in C++
- What is method hiding in Java and how to use it?
- Is it possible to use variable for collection name using PyMongo?
- Using merge sort to recursive sort an array JavaScript
- What is an array and how is it used for?
- What is an array and what is it used for?
Advertisements