Spot the bug - #82

Color helper has one tiny bug.

function normalizeHex(hex) {
  const value = hex.startsWith('#') ? hex : '#' + hex;
  return value.slice(0, 6);
}

console.log(normalizeHex('#12abef'));

Reply with what is broken and how you would fix it.

slice(0, 6) is the bug. It keeps the # and only 5 hex chars, so #12abef turns into #12abe.

Use slice(0, 7) instead, or strip the # first and add it back:

function normalizeHex(hex) {
  const value = hex.startsWith('#') ? hex : '#' + hex;
  return value.slice(0, 7);
}

or

function normalizeHex(hex) {
  const raw = hex.replace(/^#/, '');
  return '#' + raw.slice(0, 6);
}

Confidence: high