Skip to content

Instantly share code, notes, and snippets.

@hlfbt
Created November 25, 2019 04:07
Show Gist options
  • Save hlfbt/def2693765a7d5683567f91219ab6261 to your computer and use it in GitHub Desktop.
Save hlfbt/def2693765a7d5683567f91219ab6261 to your computer and use it in GitHub Desktop.
Convert Nintendo friend codes to plain old integers, for whatever reason you might want to do that anyway
function fc2int(fc) {
const codes = '0123456789ABCDEFGHJKLMNPQRSTUVWXY';
fc = fc.toUpperCase().match(new RegExp(`[${codes}]`, 'g'));
return -1 + fc
.map((a, i) => (codes.indexOf(a) + 1) * Math.pow(codes.length - 1, i))
.reduce((a, b) => a + b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment