HEX to RGB
MediumPrompt
Write a JavaScript function that takes a string representing a color in hexadecimal format and returns an object representing the equivalent color in RGB (Red, Green, Blue) format.
- The input will be a string starting with
#followed by either 3 or 6 hexadecimal characters (e.g.#fffor#0080ff). - For 3-character shorthand, each character should be doubled (e.g.
#abcbecomes#aabbcc). - The resulting object should have keys
r,g, andb, each holding a decimal number between 0 and 255. - Do not use regular expressions or external libraries.