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

fix: rgbToHsl no longer mutates its input array by InukaWijerathna · Pull Request #1908 · 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
2 changes: 1 addition & 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,7 @@ const rgbToHsl = (colorRgb) => {
throw new Error('Input is not a valid RGB color.')
}

let colorHsl = colorRgb
let colorHsl = [...colorRgb]

let red = Math.round(colorRgb[0])
let green = Math.round(colorRgb[1])
Expand Down
7 changes: 7 additions & 0 deletions Conversions/test/RgbHslConversion.test.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 @@ -40,4 +40,11 @@ describe('RgbHslConversion', () => {
])('Should return the error message.', (colorRgb, expected) => {
expect(() => rgbToHsl(colorRgb)).toThrowError(expected)
})

test('Should not mutate the input array.', () => {
const colorRgb = [24, 98, 118]
const result = rgbToHsl(colorRgb)
expect(colorRgb).toEqual([24, 98, 118])
expect(result).not.toBe(colorRgb)
})
})
Loading

Back | FazBrowse Home | New Git URL