Skip to content

#007 Remainder from Two Numbers

Adam Kubiś edited this page Mar 30, 2025 · 1 revision

Published by shahednasser

math numbers

There is a single operator in JavaScript, capable of providing the remainder of a division operation. Two numbers are passed as parameters. The first parameter divided by the second parameter will have a remainder, possibly zero. Return that value.

remainder(1, 3) ➞ 1

remainder(3, 4) ➞ 3

remainder(-9, 45) ➞ -9

remainder(5, 5) ➞ 0

Notes

  • The tests only use positive and negative integers.
  • Don't forget to return the result.

Complexity

O(1), function uses the remainder operator (%) to calculate the remainder when the first number is divided by the second. Since this involves only a single arithmetic operation, both the time and space complexities are constant.

This means that the execution time and memory usage remain the same regardless of the input size.

flowchart

Clone this wiki locally