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 | 8697 |
Total Skips | 2463 |
Total Code Submissions | 15666 |
Total Times Completed | 2771 |
Ruby Completions | 154 |
Python Completions | 838 |
JavaScript Completions | 1190 |
Clojure Completions | 72 |
Haskell Completions | 103 |
Java Completions | 303 |
C# Completions | 165 |
Go Completions | 19 |
Total Stars | 173 |
% of votes with a positive feedback rating | 93% of 581 |
Total "Very Satisfied" Votes | 504 |
Total "Somewhat Satisfied" Votes | 68 |
Total "Not Satisfied" Votes | 9 |
Total Rank Assessments | 10 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |