0

I need to populate three arrays with different values for the same range.

For ex:

Have an array like this

var arr = [1,2,3,4,5,6];

i need this array in format

a[0]=[2,3,4,1,5];
a[1]=[4,3,2,1,5];
a[2]=[2,3,1,5,4];

so three indexes of array show three different array values in order.

I am trying with this below snippets

(function($){
 $.fn.shuffle = function() {
 return this.each(function(){
 var items = $(this).children();
 return (items.length)
 ? $(this).html($.shuffle(items))
 : this;
 });
}

$.shuffle = function(arr) {
 for(
 var j, x, i = arr.length; i;
 j = parseInt(Math.random() * i),
 x = arr[--i], arr[i] = arr[j], arr[j] = x
 );
  return arr;
 }
})(jQuery);

var arr = [1,2,3,4,5,6];
a =[];
b=[];
c=[];

a = $.shuffle(arr);
b = $.shuffle(a);
c = $.shuffle(b);

document.write(a);
document.write(b);
document.write(c);
Mohan Shanmugam
  • 644
  • 1
  • 6
  • 18
  • See http://stackoverflow.com/questions/2450954/how-to-randomize-a-javascript-array Also, using jquery for this is highly unnecessary. – Sam Dufel May 08 '12 at 15:35
  • Here am not get what i need. This example solves only the one single array. But i need to derive three array from values – Mohan Shanmugam May 08 '12 at 17:19

0 Answers0