In hex you use three or six digits to define a color. By replacing all six-digit colors with the closest color which can be expressed with three digits, we save 3 bytes each! Hooray!
http://www.w3.org/TR/CSS2/syndata.html#value-def-color
The three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros.
Examples:
'00ff00' -> '0f0'
'34cf9d' -> '3c9'
@williammalo
Nope. The point is to round to the nearest color. Your code returns "011" for "001a1a" but "022" would be closer:
1a = 1*16 + 10 = 26
11 = 1_16 + 1 = 17 -> 26 - 17 = 9
22 = 2_16 + 2 = 34 -> 34 - 26 = 8
8 is smaller than 9, thus "22" is closer to "1a" than "11".