luhnChecksum2 static method

  1. @Deprecated('Use [luhnChecksum]')
int luhnChecksum2(
  1. List<int> digits
)

Calculates the Luhn checksum for a list of digits (alternative implementation).

The digits parameter is a list of digits for which the checksum is calculated. Returns the calculated Luhn checksum as an integer.

Implementation

@Deprecated('Use [luhnChecksum]')
static int luhnChecksum2(List<int> digits) {
  int sum = 0;
  for (int i = digits.length - 1; i >= 0; i--) {
    int digit = digits[i];
    if ((digits.length - i).isEven) {
      digit *= 2;
      if (digit > 9) {
        digit -= 9;
      }
    }
    sum += digit;
  }
  final checksum = (sum * 9) % 10;

  return checksum;
}