Skip to content

Instantly share code, notes, and snippets.

@extralam
Last active August 31, 2019 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save extralam/c7910c933bdd4b3fd96807a58f708dd3 to your computer and use it in GitHub Desktop.
Save extralam/c7910c933bdd4b3fd96807a58f708dd3 to your computer and use it in GitHub Desktop.
Hong Kong EPS Checksum
function eps_checksum(accNumber) {
return 10 - (accNumber.split("").map((digit, index) => digit*( Number((index+1)%2==0)+1) ).reduce((a,b)=> a+(b%10)+Number(b>10)) % 10 );
}
<?php
function eps_checksum($data){
$sum = 0;
foreach(str_split($data) as $index => $item){
$weight = (($index + 1) % 2 == 0) ? 2 : 1;
$sum += array_sum(str_split(($item * $weight)));
}
return 10 - ( $sum % 10 );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment