showing results for - "javascript ean13 checksum generate"
Alexander
05 Mar 2018
1function getLastEan13Digit(ean) { 
2  if (!ean || ean.length !== 12) throw new Error('Invalid EAN 13, should have 12 digits'); 
3  const multiply = [1, 3]; 
4  let total = 0; 
5  ean.split('').forEach((letter, index) => { 
6    total += parseInt(letter, 10) * multiply[index % 2]; 
7  }); 
8  const base10Superior = Math.ceil(total / 10) * 10; 
9  return base10Superior - total;
10}