0 of 6 problems solved0%
3 of 6

When Is It a Date?

Use instanceof for class-based checks like Date. Combine it with typeof to handle other primitives. Return a single number so callers can compare times.

function toMs(v: Date | number) {
  return v instanceof Date ? v.getTime() : v;
}

Parse strings using Date.parse which returns milliseconds since the epoch. Keep behavior simple and explicit.

Your Task

Convert different time inputs into milliseconds.

  • Write function toMillis(v: Date | number | string): number.
  • If v is a Date, return v.getTime().
  • If v is a number, return it as-is.
  • If v is a string, return Date.parse(v).