diff --git a/Conversions/RgbHslConversion.js b/Conversions/RgbHslConversion.js index 7e014f1318..d09fc76531 100644 --- a/Conversions/RgbHslConversion.js +++ b/Conversions/RgbHslConversion.js @@ -22,7 +22,8 @@ const rgbToHsl = (colorRgb) => { throw new Error('Input is not a valid RGB color.') } - let colorHsl = colorRgb + // Work on a copy so the caller's RGB array is not mutated + let colorHsl = colorRgb.slice() let red = Math.round(colorRgb[0]) let green = Math.round(colorRgb[1]) diff --git a/Sorts/BogoSort.js b/Sorts/BogoSort.js index eeb4f7feeb..2b6652fed2 100644 --- a/Sorts/BogoSort.js +++ b/Sorts/BogoSort.js @@ -12,14 +12,13 @@ export function isSorted(array) { } /** - * Shuffles the given array randomly in place. + * Unbiased Fisher–Yates shuffle of the given array in place. + * Each permutation is equally likely. */ function shuffle(array) { - for (let i = array.length - 1; i; i--) { - const m = Math.floor(Math.random() * i) - const n = array[i - 1] - array[i - 1] = array[m] - array[m] = n + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)) + ;[array[i], array[j]] = [array[j], array[i]] } }