RGB To Hex Conversion
题目
The rgb function is incomplete. Complete it so that passing in RGB decimal values will result in a hexadecimal representation being returned. Valid decimal values for RGB are 0 - 255. Any values that fall out of that range must be rounded to the closest valid value.
Note: Your answer should always be 6 characters long, the shorthand with 3 will not work here.
The following are examples of expected output values:
1 | rgb(255, 255, 255) // returns FFFFFF |
思路
需要注意的有以下几点
- 数值小于0和大于255的情况
- 数值小于16的时候转换出来的前面要加一个0
答案
1 | function rgb(r, g, b){ |

