Skip to content
intermediate

Pin it down: the cases that make a relative timestamp unambiguous

Implement this from the stub. Hidden tests grade the behaviour you write, not the comments you leave.

This site's marginalia — "last used 3m ago", "recorded your reflection 2h ago" — runs on a function like this one. Ask for "format seconds as a relative label" and you will get something that turns ten minutes into `10 minutes ago`. It will also do *something* with 30 seconds, with 90 seconds, and with exactly one minute — and each of those somethings is a decision somebody made without telling you.

export interface Case {
  deltaSeconds: number
  expected: string
}

/**
 * The cases that pin the description down.
 *
 * To pass, this list must accept the correct implementation and reject
 * each of the four wrong ones. A case whose `expected` is not what the
 * description requires will fail against the correct implementation, so
 * getting the values right is part of the exercise.
 */
export const CASES: Case[] = [
  // Your cases here
]
challenge — implement from scratchCtrl+↵ submits · Ctrl+Shift+↵ runsstarter code