Skip to content

Instantly share code, notes, and snippets.

@sntran
Created January 31, 2012 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sntran/1708258 to your computer and use it in GitHub Desktop.
Save sntran/1708258 to your computer and use it in GitHub Desktop.
CoffeeScript Implementation of the Fisher-Yates array sorting algorithm
# Refactored from git://gist.github.com/859699.git by ddgromit for swapping
fisherYates = (arr) ->
i = arr.length
if i is 0 then return false
while --i
j = Math.floor(Math.random() * (i+1))
[arr[i], arr[j]] = [arr[j], arr[i]] # use pattern matching to swap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment