Skip to content

Commit

Permalink
Fix a bug in the sort routine, mentioned at https://xerte.org.uk/inde…
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnSmith-LT committed May 3, 2022
1 parent 2e31bd9 commit 63ab5ae
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -223,7 +223,7 @@
var dropDownSort = x_currentPageXML.getAttribute("dropDownSort");
if (dropDownSort != undefined && dropDownSort != "" && dropDownSort != "alphabetic") // must be random
allAnswers.sort(
function() { return 0.5 - Math.random(); }
function() { return Math.random() - 0.5; }
);
else
allAnswers.sort();
Expand Down Expand Up @@ -723,7 +723,7 @@
}
}

var labels = $("#labelHolder .label").sort(function() { return (Math.round(Math.random())-0.5); });
var labels = $("#labelHolder .label").sort(function() { return Math.random() - 0.5; });
for (var i=0; i<labels.length; i++) {
$(labels[i])
.appendTo($("#labelHolder"))
Expand Down

4 comments on commit 63ab5ae

@FayCross
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change by @JohnSmith-LT has been reversed in @torinfo 's merge (9d3e331#diff-f101196fc8ac91bfd7066e70ad09dbac093c84e3d549b647dafccc31e09833d6) - should it be?

@JohnSmith-LT
Copy link
Collaborator Author

@JohnSmith-LT JohnSmith-LT commented on 63ab5ae Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second change definitely needs to go back @torinfo:

Math.round(Math.random())-0.5 always returns 0-0.5 = 0.5 which is why this routine never sorted. The first change was just to standardise this poor man's random sort with the same as the other one but it will still work.

@torinfo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohnSmith-LT @FayCross No, that was certainly NOT the intention...

@torinfo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put in again in 7ed814f64

Please sign in to comment.