forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRGBToHex.js
More file actions
Latest commit
21 lines (16 loc) · 400 Bytes
/
Copy pathRGBToHex.js
File metadata and controls
21 lines (16 loc) · 400 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
functionRGBToHex(r,g,b){
if(
typeofr!=='number'||
typeofg!=='number'||
typeofb!=='number'
){
thrownewTypeError('argument is not a Number')
}
consttoHex=n=>(n||'0').toString(16).padStart(2,'0')
return`#${toHex(r)}${toHex(g)}${toHex(b)}`
}
export{RGBToHex}
// > RGBToHex(255, 255, 255)
// '#ffffff'
// > RGBToHex(255, 99, 71)
// '#ff6347'