Parse HTML/CSS Colors
Description:
In this kata you parse RGB colors represented by strings. The formats are primarily used in HTML and CSS. Your task is to implement a function which takes a color as a string and returns the parsed color as a map (see Examples).
Input:
The input string represents one of the following:
6-digit hexadecimal - "#RRGGBB"
e.g. "#012345", "#789abc", "#FFA077"
Each pair of digits represents a value of the channel in hexadecimal: 00 to FF3-digit hexadecimal - "#RGB"
e.g. "#012", "#aaa", "#F5A"
Each digit represents a value 0 to F which translates to 2-digit hexadecimal: 0->00, 1->11, 2->22, and so on.Preset color name
e.g. "red", "BLUE", "LimeGreen"
You have to use the predefined mapPRESET_COLORS
(JavaScript, Python, Ruby),presetColors
(Java, C#, Haskell),PresetColors
(Go) orpreset-colors
(Clojure). The keys are the names of preset colors in lower-case and the values are the corresponding colors in 6-digit hexadecimal (same as 1. "#RRGGBB").
Examples:
parse_html_color('#80FFA0') # => { r: 128, g: 255, b: 160 }
parse_html_color('#3B7') # => { r: 51, g: 187, b: 119 }
parse_html_color('LimeGreen') # => { r: 50, g: 205, b: 50 }
Similar Kata:
Stats:
Created | Feb 28, 2017 |
Published | Feb 28, 2017 |
Warriors Trained | 8728 |
Total Skips | 2465 |
Total Code Submissions | 15706 |
Total Times Completed | 2784 |
Ruby Completions | 155 |
Python Completions | 843 |
JavaScript Completions | 1193 |
Clojure Completions | 72 |
Haskell Completions | 103 |
Java Completions | 307 |
C# Completions | 165 |
Go Completions | 21 |
Total Stars | 174 |
% of votes with a positive feedback rating | 92% of 585 |
Total "Very Satisfied" Votes | 506 |
Total "Somewhat Satisfied" Votes | 69 |
Total "Not Satisfied" Votes | 10 |
Total Rank Assessments | 10 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |