Skip to the code
cf.
+10 XP

#656 Order ID Check Digit

easy

A shop prints a one-digit check code next to each order ID. The code is found by adding up the ID's digits, then adding up the digits of that sum, and so on, until a single digit is left.

Write checkDigit(orderId) that returns that single digit.

Example 1

Input: orderId = 38
Output: 2

3 + 8 = 11, then 1 + 1 = 2.

Example 2

Input: orderId = 0
Output: 0

0 is already a single digit.

Constraints

  • 0 <= orderId <= 10^15
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).