Files
30-seconds-of-code/snippets/RGB-to-hexadecimal.md
2017-11-30 19:54:11 +02:00

10 lines
283 B
Markdown

### RGB to hexadecimal
Convert each value to a hexadecimal string, using `toString(16)`, then `padStart(2,'0')` to get a 2-digit hexadecimal value.
Combine values using `join('')`.
```js
var rgbToHex = (r, g, b) =>
[r,g,b].map( v => v.toString(16).padStart(2,'0')).join('');
```