removing duplicate code and converting it to one line using shortHex.startsWith('#') ? 1 : 0

making function more terse removing unnecessary empty strings.
This commit is contained in:
iamsoorena
2017-12-17 01:05:53 +03:30
parent 3f4af69faf
commit 7667f0d975

View File

@ -4,8 +4,7 @@ Use `Array.map()`, `split()` and `Array.join()` to join the mapped array for con
```js
const convertHex = shortHex =>
shortHex[0] == '#' ? ('#' + shortHex.slice(1).split('').map(x => x+x).join('')) :
('#' + shortHex.split('').map(x => x+x).join(''));
'#' + shortHex.slice(shortHex.startsWith('#') ? 1 : 0).split().map(x => x+x).join()
// convertHex('#03f') -> '#0033ff'
// convertHex('05a') -> '#0055aa'
```