0 of 6 problems solved0%
5 of 6

Count True in Unknown Map

Sometimes you get a dictionary with unknown values. You can treat it as a record of unknown and then check each value.

Count how many entries are exactly true. Skip everything else. Return 0 for empty input.

function countYes(m: { [k: string]: unknown }) {
  let c = 0;
  for (const k in m) if (m[k] === true) c++;
  return c;
}

Your Task

Build a function that counts true values in a map with unknown values.

  • Define interface UnknownMap { [key: string]: unknown }.
  • Implement countTrue(map: UnknownMap): number that returns the number of keys whose value is exactly true.
  • Do not mutate the input.
  • Return 0 for an empty map.