Skip to content

Instantly share code, notes, and snippets.

@surajp
Last active May 7, 2020 21:59
Show Gist options
  • Save surajp/93918b6d21cd91cadff8fb9aab9417bf to your computer and use it in GitHub Desktop.
Save surajp/93918b6d21cd91cadff8fb9aab9417bf to your computer and use it in GitHub Desktop.
Convert SF 15 char to 18 char id
(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