Skip to content

Instantly share code, notes, and snippets.

@ddgromit
Created March 8, 2011 01:56
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ddgromit/859699 to your computer and use it in GitHub Desktop.
Save ddgromit/859699 to your computer and use it in GitHub Desktop.
CoffeeScript Implementation of the Fisher-Yates array sorting algorithm
# Adapted from the javascript implementation at http://sedition.com/perl/javascript-fy.html
# Randomizes the order of elements in the passed in array in place.
fisherYates = (arr) ->
i = arr.length;
if i == 0 then return false
while --i
j = Math.floor(Math.random() * (i+1))
tempi = arr[i]
tempj = arr[j]
arr[i] = tempj
arr[j] = tempi
return arr
@coolaj86
Copy link

coolaj86 commented Dec 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment