Language: TypeScript
Difficulty: intermediate
Implement and export a TypeScript function formatTimeRemaining(ms: number): string that converts a non-negative millisecond duration into a compact human-friendly string using units d, h, m, s. Rules: use floor division; omit zero-valued units; show at most two largest non-zero units (e.g., '2d 3h', '1h 2m', '45s'); for ms <= 0 or invalid input return '0s'. Deliverable: the exported function and 3 quick assertions (examples) demonstrating the outputs. Examples: formatTimeRemaining(90061000) -> '1d 1h'; formatTimeRemaining(3723000) -> '1h 2m'; formatTimeRemaining(65000) -> '1m 5s'. Acceptance: Type-safe export, follows rules above, matches the example outputs.
solution.ts
Flawless logic but incomplete deliverable—add the three required assertions to finish!
# Clone the repository
git clone <this-repo-url>
cd <repo-name>
# Run the solution (adjust based on language)
# TypeScript: npx ts-node solution.ts
# Python: python solution.py
# Java: javac Solution.java && java SolutionExported from Flight School using GitHub Copilot SDK