Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions lib/upn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
function upn() {
//
}
function upn() {}

const multipliers = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];

Expand All @@ -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) => {
Expand All @@ -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;