This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getLastEan13Digit(ean) { | |
if (!ean || ean.length !== 12) throw new Error('Invalid EAN 13, should have 12 digits') | |
const multiply = [1, 3] | |
let total = 0 | |
ean.split('').forEach((letter, index) => { | |
total += parseInt(letter, 10) * multiply[index % 2] | |
}) |