Skip to content

Instantly share code, notes, and snippets.

@duncanbeevers
Forked from ddgromit/fisheryates.coffee
Created October 22, 2012 09:53
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 duncanbeevers/3930701 to your computer and use it in GitHub Desktop.
Save duncanbeevers/3930701 to your computer and use it in GitHub Desktop.
CoffeeScript Implementation of the Fisher-Yates array sorting algorithm
fisherYates = (array) ->
cap = array.length
for e, i in array
j = Math.floor(Math.random() * (cap - i)) + i
[ array[i], array[j] ] = [ array[j], e ] unless i == j
array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment