DEV Community

Discussion on: Build a Card Memory Game with React

Collapse
 
pengeszikra profile image
Peter Vivo • Edited

Functional shuffle array

const shuffle = () => Math.random() > 0.5 ? 1 : -1;

const shuffledCards = cards.sort(shuffle);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
cswalker21 profile image
cswalker21

Interesting. It’s certainly elegant, and definitely suitable for many applications, including this memory game. I’m not schooled up enough on combinatorics to know at first blush if this method produces an unbiased distribution compared to the algorithm mentioned in the article.