Skip to content

Instantly share code, notes, and snippets.

@jcfausto
Created November 2, 2015 17:28
Show Gist options
  • Save jcfausto/51cb5ebce14a9faf218e to your computer and use it in GitHub Desktop.
Save jcfausto/51cb5ebce14a9faf218e to your computer and use it in GitHub Desktop.
Coffeescript code to shuffle an array of strings in random order
###
# 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