vendredi 18 mai 2018

Produce an array containing pairs in a random order [on hold]

In Javascript I am aiming to produce an array containing pairs in a random order. The result should look something like this:

numbers = [1, 4, 3, 5, 1, 4, 5, 2, 3, 2, 6, 6];

The criterias:

  • The array should always consist of 12 numbers.
  • Accepted number value is from 1 to 6.
  • Every number should always exists twice within the array.
  • The order of the number should always be spread random within the array.
  • The function should be minimised and dry, avoiding code duplication.

So far I know how to produce one random number and of course you could create several random numbers, but I do not know how to create rules and cycle that would take above criterias into consideration and populate an array in a proper way. Below is one example of how to create the "one random number" function:

randomNumber = (Math.floor(Math.random() * 6) + 1);




Aucun commentaire:

Enregistrer un commentaire