Skip to content

Instantly share code, notes, and snippets.

@RMuskovets
Created September 14, 2019 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RMuskovets/3c72571d083fb3c544bcecd3f10fde4b to your computer and use it in GitHub Desktop.
Save RMuskovets/3c72571d083fb3c544bcecd3f10fde4b to your computer and use it in GitHub Desktop.
This is a very small parseInt realisation in 153 bytes written in JavaScript.
const parseInt=(s,r=10)=>{const a=['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
const as=a.slice(0,r+1);let v=0,n=s[0]=='-';for (let i=n?1:0;i<s.length;i++)v=v*r+as.indexOf(s[i]);if(n)v*=-1;return v};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment