Created
November 2, 2015 17:28
-
-
Save jcfausto/51cb5ebce14a9faf218e to your computer and use it in GitHub Desktop.
Coffeescript code to shuffle an array of strings in random order
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
### | |
# Given an Array of Strings | |
# This function will shuffle the String inside the array | |
# Created by: Julio Cesar Fausto | |
# http://github.com/jcfausto | |
### | |
phrases = [ | |
'phrase1' | |
'phrase2' | |
'phrase3' | |
'phrase4' | |
] | |
shuffle: -> | |
phrases_count = phrases.lenght | |
while phrases_count | |
random_index = Math.floor(Math.random() * phrases_count) | |
random_phrase = phrases[--phrases_count] | |
phrases[phrases_count] = phrases[random_index] | |
phrases[random_index] = random_phrase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment