Created
May 15, 2020 18:07
-
-
Save petersg83/57f6a909ad8bd04b860335f60c2da895 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const MULTIPLIERS = [1, 2, 1, 2, 1, 2, 1, 2, 1]; | |
const isValid = (sin) => { | |
if (typeof sin !== 'string' || sin.length !== 9) { | |
return false; | |
} | |
splitedSin = sin.split('').map(Number); | |
const digits = splitedSin.reduce((allDigits, val, index) => { | |
const result = String(val * MULTIPLIERS[index]).split(''); | |
return [...allDigits, ...result]; | |
}, []); | |
const key = digits.reduce((sum, digit) => sum + Number(digit), 0); | |
return key % 10 === 0; | |
} | |
console.log(isValid('046454286')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment