Jump to content

Harmjan

Members
  • Content Count

    1
  • Joined

  • Last visited

Everything posted by Harmjan

  1. https://www.w3schools.com/js/tryit.asp?filename=tryjs_array_sort_random This code doesn't create a randomly ordered list: var points = [40, 100, 1, 5, 25, 10]; points.sort(function(a, b){return 0.5 - Math.random()}); When I run it multiple times and check on which index the 40 ended up, I get the following distribution: 29 %,16%, 10%, 11%, 14%, 19%. I think it's dangerous to teach people a trick that doesn't work. Full code: <!DOCTYPE html> <html> <body> <h2>JavaScript Array Sort</h2> <p>Click the button (again and again) to
×
×
  • Create New...