Write a js function to convert color in #fff (short) format to #ffffff
- User
Write a js function to convert color in #fff (short) format to #ffffff
Assistant
Here's a JavaScript function to convert a color from #fff short format to #ffffff long format:
jsfunction expandColor(color) { if (color.length === 4) { color = color.replace(/./g, '$&$&'); } return color; } expandColor('#fff'); // #ffffff expandColor('#000'); // #000000 expandColor('#abc'); // #aabbccThis checks if the color code is 4 characters long, and if so, replaces each character with that character repeated twice, to expand it to 6 characters.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.