The points.sort() method depicted in the example above may not yield accurate results, as it could favor certain numbers over others.
One of the most commonly used correct methods is known as the Fisher-Yates shuffle, which has been employed in data science since as early as 1938!
In JavaScript, this method can be implemented as follows:
Example
const points = [40, 100, 1, 5, 25, 10]; for (let i = points.length –1; i > 0; i–) { let j = Math.floor(Math.random() * (i+1)); let k = points[i]; points[i] = points[j]; points[j] = k; } |
Built-in functions for identifying the maximum or minimum value in an array are not available.To determine the lowest or highest value, you have three alternatives: