Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Floor, Ceil, Trunc

Numbers, Dates & Timersmedium

Course · Section 12: Numbers, Dates, Intl and Timers · Lecture 182: Math and Rounding

Implement `roundModes(n)` returning `[floor, ceil, truncated]` for `n`.

Sample tests

Input: roundModes(4.7)
Output: [4,5,4]
Input: roundModes(-4.7)
Output: [-5,-4,-4]

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • floor and trunc differ for negative numbers.
Approach & explanation (try first)

floor rounds down, ceil rounds up, and trunc cuts toward zero, which diverge for negatives.

Loading...
⌘/Ctrl + Enter

Run your code to see results.