Skip to content

Instantly share code, notes, and snippets.

@nblackburn
Created May 29, 2019 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nblackburn/9bd24959f148cb046ae4206502916358 to your computer and use it in GitHub Desktop.
Save nblackburn/9bd24959f148cb046ae4206502916358 to your computer and use it in GitHub Desktop.
module.exports = (red, green, blue, preferShorthand = false) => {
let colours = [red, green, blue].map(value => value.toString(16));
let canBeCondensed = colours.every(value => value.charAt(0) === value.charAt(1));
if (canBeCondensed && preferShorthand) {
colours = colours.map(v => v.charAt(0));
}
return '#' + colours.join('');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment