Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Order ID Encoder / Decoder

node v14.20.1
version: 1.0.0
endpointsharetweet
const chars = 'abcdehlkmrtwxyz'.toUpperCase() const to = (decimal) => { let out = '' while (true) { let remainder = (decimal - 1) % chars.length out = chars[remainder] + out; decimal = Math.floor((decimal - 1) / chars.length); if (decimal === 0) break } return out; } const from = (alpha) => { const crs = chars.split('') const letters = alpha.split('') let out = 0 for (let i = 0; i < letters.length; i++) { let indexPos = crs.indexOf(letters[letters.length - 1 - i]) out += (indexPos + 1) * Math.pow(crs.length, i) } return out } module.exports = { to, from }
console.log(to(123123))
console.log(from('BHLCC'))
Loading…

no comments

    sign in to comment