← all problems

isLuhnValid 🌶️🌶️🌶️

The Luhn algorithm is a checksum used to catch typos in card numbers. Write a method that takes one String parameter, digits, made up only of digit characters, and returns true if it passes the Luhn check, or false otherwise.

To perform the check:

1) Working from the RIGHTMOST digit and moving left, double every second digit (the 2nd, 4th, 6th, ... from the right); if a doubled value is greater than 9, subtract 9 from it.
2) After step 1, sum every digit. This value is called a checksum.
3) The number is valid exactly when that checksum is a multiple of 10.