All files hexToRgb.ts

100% Statements 7/7
100% Branches 6/6
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12  1x 4x 12x       12x 12x 12x    
// https://www.codewars.com/kata/513e08acc600c94f01000001
export default function rgb(r: number, g: number, b: number): string {
	const hexParts = [r, g, b];
	return hexParts.map(part => hexPartConvert(part)).join('');
}
 
function hexPartConvert(colorInt: number): string {
	colorInt = colorInt > 255 ? 255 : colorInt < 0 ? 0 : colorInt;
	const hexPart: string = colorInt.toString(16).toUpperCase();
	return hexPart.length === 2 ? hexPart : `0${hexPart}`;
}