Last active
March 9, 2018 11:03
-
-
Save karl-gustav/9f983efb82de6adfe4e49923308526ff to your computer and use it in GitHub Desktop.
validate if number is valid Norwegian organisation number
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
function isOrgNumberValid(orgNumber) { | |
if (orgNumber.toString().length != 9) { | |
return false; | |
} | |
const wheightNumbers = [3, 2, 7, 6, 5, 4, 3, 2]; | |
const orgNumbers = orgNumber.toString().split(''); | |
const controlDigit = orgNumbers[orgNumbers.length - 1] | |
const result = wheightNumbers.map((n, i) => n * orgNumbers[i]).reduce((a, b) => a+b, 0) | |
const rest = result % 11; | |
return +controlDigit === rest; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Debug version: