From f6d61ade76e53b189b628c5710564f2d514aaf7f Mon Sep 17 00:00:00 2001 From: David Wu Date: Fri, 15 Dec 2017 14:34:55 +0100 Subject: [PATCH] Create 3DigHexcode-to-6DigHexcode.md --- snippets/3DigHexcode-to-6DigHexcode.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 snippets/3DigHexcode-to-6DigHexcode.md diff --git a/snippets/3DigHexcode-to-6DigHexcode.md b/snippets/3DigHexcode-to-6DigHexcode.md new file mode 100644 index 000000000..d424f41cd --- /dev/null +++ b/snippets/3DigHexcode-to-6DigHexcode.md @@ -0,0 +1,12 @@ +### 3DigHexcode to 6DigHexcode + +Use `Array.map()` to map the array created by `String.split()` and `Array.join()` to join +the mapped array for converting a three-digit RGB notated hexadecimal colorcode to the six-digit form. + +```js +const convertHex = shortHex => + shortHex[0] == '#' ? ('#' + shortHex.slice(1).split('').map(x => x+x).join('')) : + ('#' + shortHex.split('').map(x => x+x).join('')) +// convertHex('#03f') -> '#0033ff' +// convertHex('05a') -> '#0055aa' +```