Steps to convert 3-digit color code to 6-digit color code:
Step 1: The color code is in string format. So, apply the split method on the string. After applying the split method we got an array of elements.
["#", "3", "9", "E"]
Step 2: Now apply the map method and iterate over the array and return every item with concatenating to itself and check if the item is “#” then do not return the concatenated result, just return the item.
["#", "33", "99", "EE"]
Step 3: Now use the join method to convert all the array items into a single string.
Step 4: In the above step, we are converting “#39E” but we can see the first element of this code is “#”, but if the user does not provide the “#” then you have to check if the first element is “#” then concatenate it with the resulting code. And this is our complete code.