MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / RGBToHex

Function RGBToHex

Conversions/RGBToHex.js:1–9  ·  view source on GitHub ↗
(r, g, b)

Source from the content-addressed store, hash-verified

1function RGBToHex(r, g, b) {
2 if (typeof r !== 'number' || typeof g !== 'number' || typeof b !== 'number') {
3 throw new TypeError('argument is not a Number')
4 }
5
6 const toHex = (n) => (n || '0').toString(16).padStart(2, '0')
7
8 return `#${toHex(r)}${toHex(g)}${toHex(b)}`
9}
10
11export { RGBToHex }
12

Callers 1

RGBToHex.test.jsFile · 0.90

Calls 1

toHexFunction · 0.85

Tested by

no test coverage detected