-
-
Save neoneo40/cd6a64d19ebac60d62c1 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
"use strict"; | |
var input = '13자리의 주민번호 - 없이'; | |
var mul = [2,3,4,5,6,7,8,9,2,3,4,5]; | |
var sum = 0; | |
for(var i =0; i < mul.length; i++) { | |
var digit = parseInt(input[i]); | |
sum += digit * mul[i]; | |
} | |
var eleven_spare = sum % 11; | |
var confirm_num = 11 - eleven_spare; | |
if(confirm_num > 9) { | |
confirm_num -= 10; | |
} | |
if(confirm_num == parseInt(input[input.length - 1])) { | |
console.log('맞는 주번인듯'); | |
} | |
else { | |
console.log('코드는 : ' + confirm_num); | |
console.log('틀린주번아냐?') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment