Skip to content

.toString(36) not properly/fully implemented #527

Description

@the-hotmann

I also encountered this error:

https://stackoverflow.com/a/52524228

I was about to implement this TS function:

function getToken(id: string) {
  return ((Number(id) / 1e15) * Math.PI).toString(36).replace(/(0+|\.)/g, '')
}

in golang and wanted to use JS interpreter as validation. But it does not work as expected.

When I run it for the a twitter ID, it does just generate the first "part" of the result.
Everything after and including the dot, is missing (the dot gets removed anyway), but the token after the dot is missing as well.

Expected result:

4dh7jvecqt6

actual result:

4dh

Here what this function does:

  1. take a string
  2. convert to float64 (maybe float36? - not too sure about this one)
  3. floatNum := (num / 1e15) * math.Pi
  4. convert float to base36
  5. remove all zeros and dots (0 & .)

That is all. But this tool, does not do this properly, it converts the string to an int and converts the int to base36. Which is missing some operations.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions