Better Hex Color Codes for Your Internet Hex triplets such as #ffffff (white) or #3764ef (blueish) are often used to denote RGB colors. They consist of # followed by six hexadecimal digits (0-f), or sometimes three digits where the real color is obtained by doubling each digit. For example, #fff is #ffffff and #1a8 is #11aa88.

Sadly, that three digit shorthand was the golfiest the internet had to offer, until now.

Write a program or function that takes in a string of 1 to 7 characters:


The first character will always be #.
The other characters will always be hexadecimal digits: 0123456789abcdef.


The input is a shorthand form of a hex triplet (or the full form if 7 characters are given).
You need to output a full hex triplet that expands the input shorthand based on these patterns:

Input   -&gt; Output
#       -&gt; #000000    (black)
#U      -&gt; #UUUUUU
#UV     -&gt; #UVUVUV
#UVW    -&gt; #UUVVWW    (usual 3-digit shorthand)
#UVWX   -&gt; #UXVXWX
#UVWXY  -&gt; #UVWXYY
#UVWXYZ -&gt; #UVWXYZ    (not shorthand)


Each of U, V, W, X, Y, and Z may be any hexadecimal digit. The output is always 7 characters.

For example:

Input -&gt; Output
# -&gt; #000000
#0 -&gt; #000000
#4 -&gt; #444444
#f -&gt; #ffffff
#a1 -&gt; #a1a1a1
#0f -&gt; #0f0f0f
#99 -&gt; #999999
#1a8 -&gt; #11aa88
#223 -&gt; #222233
#fff -&gt; #ffffff
#1230 -&gt; #102030
#d767 -&gt; #d77767
#bbb5 -&gt; #b5b5b5
#aabbc -&gt; #aabbcc
#00000 -&gt; #000000
#3764e -&gt; #3764ee
#3764ef -&gt; #3764ef
#123456 -&gt; #123456
#f8f8f8 -&gt; #f8f8f8


Notes


The input will always start with # and so must the output.
You may assume all input letters are lowercase (abcdef) or uppercase (ABCDEF) as you prefer.
Letters in the output may be in either case as you prefer. You can even mix cases.
Alpha/transparency is not dealt with here (though there are hex versions of RGBA colors).


The shortest code in bytes wins.
JavaScript, 86 82 77 bytes

x=&gt;([s,a=0,b=a,c,d,e,f]=x,f?x:e?x+e:[s,a,d||a,c?b:a,d||b,v=c||b,d||v].join``)


just find out that remove recursive save 4 bytes...

idea from @Arnauld save 4 bytes, +1 more bytes