Created
June 19, 2012 13:45
-
-
Save tcelestino/2954305 to your computer and use it in GitHub Desktop.
Hexdecimal Contraction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//authors: Diego Fleury and Diego Nunes | |
function hexContraction(color) { | |
var regexp = /#?([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3/i; | |
return '#'+ color.replace(regexp, '$1$2$3') || '#'+ color.replace('#', ''); | |
} | |
hexContraction('aabbcc'); //#abc | |
hexContraction('#AD8634'); //'#AD8634 | |
hexContraction('aaddc4'); //#aaddc4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
O return do final poderia ser simplificado com...
return '#'+ (color.replace(regexp, '$1$2$3') || color.replace('#', ''));