Click to See Complete Forum and Search --> : Sentence Scrambler


code?
March 19th, 2008, 06:32 AM
Is it possible to have a sentence scrambler in javascript? I've seen tons of scripts in PHP but I know in JS all you have to do is:

1. Split the strings by ' '.
2. Put the strings in an array.
3. Scramble
4. Loop through array and write strings out.

But then how do you preform the "scramble", or is there an easier way.

PeejAvery
March 19th, 2008, 08:13 AM
You already stated the steps perfectly. Why don't you just implement it. The functions are almost identical to PHP.

1. string.split('delimiter')
2. array.sort(function() {return 0.5 - Math.random();})
3. array.join(' ')

code?
March 19th, 2008, 02:57 PM
Ok, thanks. I was looking for some function to do the scramble and step two did it perfectly.