Javascript array shuffle shouldn't output two next to eachother -


I have found an array that is full of characters see examples below. I first know that the array is shuffling. Well I found it the most famous shuffle called Fisher-Yates Firbadal.

Now I want to do this output, eg. F2 should not be next to F and F ' and the other goes to D D 2 or D '.

It outputs such as: RB2 UFLF D2 ... and so on.

No more: R B2B ' LF D2 ...

Any help, suggestions? I know that I should check the first character with charite () , but I am not an expert at that function.

Javascript function shuffle (side) {in the context of var elements = sides.length, temp, randomIndex, last; While (determining elements> 1) {randomIndex = Math.floor (Math.random () * elementsRemaining--); If (randomIndex! = ElementsRemaining) {temp = sides [edit the elements]; Party [determining elements] = side [random index]; Party [random index] = temporary; }}; Return party; } "Side", "U2", "L2", "D2", "U2", "R", "U2", "R", "U", "L", "D", "F2" , "F" "R", "U", "L", "D" "]; (Sides) shuffle; $ ('# Conflict') HTML (sides).

You can drag, check your obligation and if not obstruct If so, then repeat. Your method can be used to check constraints

  var passesConstraint = function (side) {for (var i = 0; i & lt; sides.length - 1; i ++) {if (Side [i] [0] === side [i + 1] [0]) {return false; }} Be true; }   

You do not need to fill (), strings can also be accessed by [] notation.

  Shuffle (side) while (! PassesConstraint (side)) {alteration (side)}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -