Shuffle Algorithm for Array of numbers

by Konstantin Rouda

HTML

<!-- 
Inspired by:

https://blog.codinghorror.com/the-danger-of-naivete/
-->

JavaScript

;(function () {
	"use strict";
  
  /// shuffle algorithm
  
  
  var arr = [1, 2, 3, 4, 5];
  
  console.log("unshuffled array: ", arr);
  
  for(var i = arr.length - 1; i >= 0; i--) {
    var ranNumb = Math.floor(Math.random() * (i + 1));
    debugger;
    shuffle(arr, i, ranNumb);
  };
  
  console.log("===========================================");

  function shuffle (arr, firstCardIndex, secondCardIndex) {
     var first = arr[firstCardIndex];
     var second = arr[secondCardIndex];
     arr[firstCardIndex] = second;
     arr[secondCardIndex] = first;
     debugger;
  }

  console.log("shuffled array: ", arr);
  
  
})();