Skip to content

Instantly share code, notes, and snippets.

@westc
Created September 1, 2018 04:42
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 westc/8069af4c97dd6dd1148e271d0314aba2 to your computer and use it in GitHub Desktop.
Save westc/8069af4c97dd6dd1148e271d0314aba2 to your computer and use it in GitHub Desktop.
YourJS candidate functions: int8(), uint8(), int16(), uint16(), int32(), and uint32()
// Creates the following functions: int8(), uint8(), int16(), uint16(), int32(), and uint32()
// The int functions convert a number into a signed integer that can be represented by the number of bits specified by the function name (int8() returns 8-bit signed integers).
// The uint functions convert a number into an unsigned integer that can be represented by the number of bits specified by the function name (uint8() returns 8-bit unsigned integers).
eval('uUi32I32uUi16I16uUi8I8'.replace(/(u?)([UI]i?)(\d\d?)/g, 'var $1int$3;(function(a){$1int$3=function(x){return a[0]=x,a[0]}})(new $2nt$3Array(1));'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment