Skip to content

Instantly share code, notes, and snippets.

@Asgarrrr
Created October 16, 2021 11:40
Show Gist options
  • Save Asgarrrr/ed08b27ed4ffcf56c117d0fcc78d0a77 to your computer and use it in GitHub Desktop.
Save Asgarrrr/ed08b27ed4ffcf56c117d0fcc78d0a77 to your computer and use it in GitHub Desktop.
RGB to HEX
const rgbToHex = ( r, g, b ) => "#" + [ r, g, b ].map( ( x ) => {
const hex = x.toString( 16 )
return hex.length === 1 ? "0" + hex : hex
}).join( "" );
rgbToHex( 102, 51, 153 ); // #663399
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment