From 7667f0d975a325b8501233adb3908e209048a422 Mon Sep 17 00:00:00 2001 From: iamsoorena Date: Sun, 17 Dec 2017 01:05:53 +0330 Subject: [PATCH] removing duplicate code and converting it to one line using `shortHex.startsWith('#') ? 1 : 0` making function more terse removing unnecessary empty strings. --- snippets/3-digit-hexcode-to-6-digit-hexcode.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/snippets/3-digit-hexcode-to-6-digit-hexcode.md b/snippets/3-digit-hexcode-to-6-digit-hexcode.md index a138b34bb..17a4561db 100644 --- a/snippets/3-digit-hexcode-to-6-digit-hexcode.md +++ b/snippets/3-digit-hexcode-to-6-digit-hexcode.md @@ -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' ```