A color picker accepts CSS hex colors and shows their red, green, and blue values. A hex color is # followed by 6 hex digits (#rrggbb) or 3 hex digits (#rgb, where each digit is doubled, so #abc means #aabbcc). Letters may be upper or lower case.
Write hexToRgb(hex) that returns [red, green, blue], each from 0 to 255.
Input: hex = "#1a2b3c" Output: [26,43,60]
1a = 1 × 16 + 10 = 26, 2b = 43, and 3c = 60.
Input: hex = "#fff" Output: [255,255,255]
#fff means #ffffff, and ff = 15 × 16 + 15 = 255.
hex is a valid 4- or 7-character hex color.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #653 Hex Color to RGB. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.