From 9329d3ec3995464d5c7c4c3b195f02dbe89fded6 Mon Sep 17 00:00:00 2001 From: boon-cpu <60711166+boon-cpu@users.noreply.github.com> Date: Wed, 16 Dec 2020 10:41:11 +0000 Subject: [PATCH] Update upn.js Just cleaning up this code a bit. --- lib/upn.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) 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;