Let's consider I have the following characters:
H, M, L
I would like to create sorted array(s) like the following:
var array1 = [ "H", "M", "L", "L", "M", "H" ];
What I don't want is for the first three and last three characters containing more than one unique character when I shuffle() the array.
e.g.
var wrong = [ "H", "M", "M", "H", "M", "L" ]; // note the two M's in the first three values
If I use shuffle() like the following:
var array2 = array1.shuffle(); then I run the risk of duplicate characters.
I would like some help in determining the easiest way to ensure there are no duplicated characters in the 1st and 2nd three values in the array?
EDIT: Changed random to sorted.
var a = ['H', 'M', 'L']; var b = a.slice().shuffle().concat(a.slice().shuffle());perhaps?