DEV Community

Discussion on: Daily Challenge #236 - RGB to Hex Conversion

Collapse
 
kenbellows profile image
Ken Bellows

JavaScript:

function rgb(r, g, b) {
  return [r,g,b].map(n => 
    Math.max(0, Math.min(255, n))
      .toString(16)
      .padStart(2, '0')
      .toUpperCase()
  ).join('')
}