From 92ce0e528f357599ffdac4a5e191e19cc89847d4 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 15 Dec 2017 14:36:23 +0200 Subject: [PATCH] Update hexcode-to-RGB.md --- snippets/hexcode-to-RGB.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/snippets/hexcode-to-RGB.md b/snippets/hexcode-to-RGB.md index 9ca5c7447..852a25ff8 100644 --- a/snippets/hexcode-to-RGB.md +++ b/snippets/hexcode-to-RGB.md @@ -1,10 +1,8 @@ ### Hexcode to RGB -Converts hexadecimal colorcodes to RGB colorcodes by matching the hexidecimal (two-digit) red, green and blue values and -mapping their decimal equivalents to an array [r, g, b]. Returns a string `rgb(r,g,b)`. +Use `Array.slice()`, `Array.map()` and `match()` to convert a hexadecimal colorcode (prefixed with `#`) to a string with the RGB values. ```js const hexToRgb = hex => `rgb(${hex.slice(1).match(/.{2}/g).map(x => parseInt(x, 16)).join()})` // hexToRgb('#27ae60') -> 'rgb(39,174,96)' -// hexToRgb('#aaa') -> '[170, 170, 170]' ```