Created
January 31, 2012 02:09
-
-
Save sntran/1708258 to your computer and use it in GitHub Desktop.
CoffeeScript Implementation of the Fisher-Yates array sorting algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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