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.
Input: orderId = 38 Output: 2
3 + 8 = 11, then 1 + 1 = 2.
Input: orderId = 0 Output: 0
0 is already a single digit.
0 <= orderId <= 10^15Run 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).
I'm here to help with #656 Order ID Check Digit. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.