FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: unbiased Fisher-Yates in bogoSort; do not mutate RGB input by zeeshanzzz788 · Pull Request #1912 · TheAlgorithms/JavaScript · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 2 additions & 1 deletion Conversions/RgbHslConversion.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
11 changes: 5 additions & 6 deletions Sorts/BogoSort.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
}
}

Expand Down
Loading

Back | FazBrowse Home | New Git URL