- Home
- Javascript
- Utilities and Helpers for our Quiz App
Building Utilities and Helpers for our Quiz App
Utilities and Helpers for our Quiz App
shuffle.js
In src/utils/shuffle.js:
const shuffle = (array) => {
const newArr = [...array];
for (let i = newArr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[newArr[i], newArr[j]] = [newArr[j], newArr[i]];
}
return newArr;
};
export default shuffle;

