Created
August 31, 2019 07:00
-
-
Save alexrqs/23e053f53c956bc11fc329e539879e5c to your computer and use it in GitHub Desktop.
RGB function with params per color to string
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
const normalColor = number => number > 255 ? 255 : number < 0 ? 0 : number | |
const toHEX = color => Number(normalColor(color)).toString(16).toUpperCase() | |
const normalHEX = hex => ((hexi = toHEX(hex)) => hexi.toString().length < 2 ? '0' + hexi : hexi)() | |
const rgb = (r,g,b) => normalHEX(r) + normalHEX(g) + normalHEX(b) | |
Test.assertEquals(rgb(0, 0, 0), '000000') | |
Test.assertEquals(rgb(0, 0, -20), '000000') | |
Test.assertEquals(rgb(300,255,255), 'FFFFFF') | |
Test.assertEquals(rgb(173,255,47), 'ADFF2F') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment