Modified Fisher-Yates array shuffling algorithm

export function shuffleArray(array, n) {
let i = array.length - 1;
for (; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
if(i === n || j === n) continue;
let temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
componentDidMount() {              
const shuffledPosts = shuffleArray(this.state.board, 12)
this.setState({
board: shuffledPosts
});
}

--

--

--

Software Dev, qualified lawyer, salesman, pro telemarketer, travel bug, meditator/energy healer, self help enthusiast, aspiring Tech Entrepreneur & family man

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

An Angular 5 Tutorial: Step by Step Guide to Your First Angular 5 App

How to build a Realtime Graph using JavaScript and Pusher

Phase-1 JavaScript Project

How to Retrieve the Public Holidays for a Country in Node.JS

Leet Code 1 Two-Sum

How we are using Sentry for mobile apps

Create an online IDE with Angular 6 + NodeJS ~ Part #1

Creating A WordPress Login In React Native

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
2 Minute Tech Reads

2 Minute Tech Reads

Software Dev, qualified lawyer, salesman, pro telemarketer, travel bug, meditator/energy healer, self help enthusiast, aspiring Tech Entrepreneur & family man

More from Medium

Getting Started with Typescript, Why Typescript over JavaScript

How to managed states globaly with context?

The Horsepower of the V8 JavaScript Engine

CRUD Operations