Last active
May 7, 2020 21:59
-
-
Save surajp/93918b6d21cd91cadff8fb9aab9417bf to your computer and use it in GitHub Desktop.
Convert SF 15 char to 18 char id
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
(inp) => | |
((elements) => | |
inp.length != 15 | |
? Error("invalid id") | |
: inp + | |
Object.values(elements) | |
.map((a) => "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345".charAt(a)) | |
.join(""))( | |
inp.split("").reduce( | |
(op, curr, index) => { | |
curr >= "A" && | |
curr <= "Z" && | |
(op[Math.floor(index / 5)] += 1 << index % 5); | |
return op; | |
}, | |
{ 0: 0, 1: 0, 2: 0 } | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment