diff --git a/lib/upn.js b/lib/upn.js index 0ab33bf..0365ad5 100644 --- a/lib/upn.js +++ b/lib/upn.js @@ -1,6 +1,4 @@ -function upn() { - // -} +function upn() {} const multipliers = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; @@ -9,12 +7,10 @@ const letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', function calculateScore(input) { const total = input.split('').reduce((accumulator, part, index) => { - const number = parseInt(part, 10); - - return accumulator + (number * multipliers[index]); + return accumulator + (parseInt(part) * multipliers[index]); }, 0); - return total % 23; + return total % letters.length; } upn.prototype.validate = (input) => { @@ -28,10 +24,8 @@ upn.prototype.validate = (input) => { }; upn.prototype.generate = () => { - const number = `${Math.round(Math.random() * 1000000000000)}`; - const letter = letters[calculateScore(number)]; - - return `${letter}${number}`; + const number = `${Math.round(Math.random() * 1000000000000)}` + return `${letters[calculateScore(number)]}${number}`; }; module.exports = upn;