Files
30-seconds-of-code/snippets/extendHex.md
Angelos Chalaris 0425ebefe7 Archive, multitagging, cleanup
Cleaned up the current snippets for consistency and minor problems, added multiple tags to most of them, archived a few.
2018-01-05 16:33:54 +02:00

22 lines
540 B
Markdown

### extendHex
Extends a 3-digit color code to a 6-digit color code.
Use `Array.map()`, `String.split()` and `Array.join()` to join the mapped array for converting a 3-digit RGB notated hexadecimal color-code to the 6-digit form.
`Array.slice()` is used to remove `#` from string start since it's added once.
```js
const extendHex = shortHex =>
'#' +
shortHex
.slice(shortHex.startsWith('#') ? 1 : 0)
.split('')
.map(x => x + x)
.join('');
```
```js
extendHex('#03f'); // '#0033ff'
extendHex('05a'); // '#0055aa'
```