Skip to content

Instantly share code, notes, and snippets.

@chankruze
Created September 30, 2021 10:05
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 chankruze/5b0b2d86d3788b3bebf5ef4e4ae966ea to your computer and use it in GitHub Desktop.
Save chankruze/5b0b2d86d3788b3bebf5ef4e4ae966ea to your computer and use it in GitHub Desktop.
const rgb2hex = (...args) => {
const hexColour = (c) => {
if (c < 256) return Math.abs(c).toString(16).padStart(2, "0");
return 0;
}
let hex = "#";
args.forEach(val => hex += hexColour(val))
return hex
}
console.log(rgb2hex(10, 255, 255))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment