Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toInteger #790

Open
char0n opened this issue Jan 1, 2019 · 0 comments
Open

toInteger #790

char0n opened this issue Jan 1, 2019 · 0 comments

Comments

@char0n
Copy link
Owner

char0n commented Jan 1, 2019

Is your feature request related to a problem? Please describe.
Converts value to an integer.

Describe the solution you'd like

toInteger(3.2); // => 3
toInteger(Number.MIN_VALUE); // => 0
toInteger(Infinity); //=> 1.7976931348623157e+308
toInteger('3.2'); // => 3

Possible implementation

const toInteger = curry1(val => {
  const finite = toFinite(val);
  const remainder = modulo(val, 1);

  return finite !== finite
   ? 0
   : remainder !== 0
   ? finite - remainder
   : finite;
});

Describe alternatives you've considered

Additional context

blocked by toFinite

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

No branches or pull requests

1 participant