Skip to content

Instantly share code, notes, and snippets.

@jcfausto
Created November 2, 2015 17:30
Show Gist options
  • Save jcfausto/60f449ddcd9a5eac32ac to your computer and use it in GitHub Desktop.
Save jcfausto/60f449ddcd9a5eac32ac to your computer and use it in GitHub Desktop.
/*
* Given an Array of Strings
* This function will shuffle the String inside the array
* Created by: Julio Cesar Fausto
* http://github.com/jcfausto
*/
var phrases, phrases_count, random_index, random_phrase;
phrases = ['phrase1', 'phrase2', 'phrase3', 'phrase4'];
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;
}
console.log(phrases);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment