From fce4b2b0f3c040f8b0d443001d01738b21d8ad67 Mon Sep 17 00:00:00 2001 From: David Wu Date: Fri, 15 Dec 2017 14:34:55 +0100 Subject: [PATCH 1/2] 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' +``` From 69e8f840753b54184f735ca3f379765bf9d1ad63 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 16 Dec 2017 13:40:52 +0200 Subject: [PATCH 2/2] Update 3DigHexcode-to-6DigHexcode.md --- snippets/3DigHexcode-to-6DigHexcode.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/snippets/3DigHexcode-to-6DigHexcode.md b/snippets/3DigHexcode-to-6DigHexcode.md index d424f41cd..2e9b9b8fc 100644 --- a/snippets/3DigHexcode-to-6DigHexcode.md +++ b/snippets/3DigHexcode-to-6DigHexcode.md @@ -1,12 +1,11 @@ ### 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. +Use `Array.map()`, `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('')) + ('#' + shortHex.split('').map(x => x+x).join('')); // convertHex('#03f') -> '#0033ff' // convertHex('05a') -> '#0055aa' ```