How to do RGB To Hex Conversion in Rust
The challenge
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:
The solution in Rust
Option 1:
Option 2:
Option 3:
Test cases to validate our solution
|
|