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
17 lines (12 loc) · 385 Bytes
/
Copy pathRGBToHex.js
File metadata and controls
17 lines (12 loc) · 385 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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'