main
Last change
on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
870 bytes
|
Line | |
---|
1 | import { bind, curryN } from 'ramda';
|
---|
2 |
|
---|
3 | import ponyfill from './internal/ponyfills/Math.trunc';
|
---|
4 | import isFunction from './isFunction';
|
---|
5 |
|
---|
6 | export const truncPonyfill = curryN(1, ponyfill);
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * Returns the integer part of a number by removing any fractional digits.
|
---|
10 | *
|
---|
11 | * @func trunc
|
---|
12 | * @memberOf RA
|
---|
13 | * @since {@link https://char0n.github.io/ramda-adjunct/2.15.0|v2.15.0}
|
---|
14 | * @category Math
|
---|
15 | * @sig Number | String -> Number
|
---|
16 | * @param {number|string} number The number to trunc
|
---|
17 | * @return {number} The integer part of the given number
|
---|
18 | * @example
|
---|
19 | *
|
---|
20 | * RA.trunc(13.37); //=> 13
|
---|
21 | * RA.trunc(42.84); //=> 42
|
---|
22 | * RA.trunc(0.123); //=> 0
|
---|
23 | * RA.trunc(-0.123); //=> -0
|
---|
24 | * RA.trunc('-1.123'); //=> -1
|
---|
25 | * RA.trunc(NaN); //=> NaN
|
---|
26 | * RA.trunc('foo'); //=> NaN
|
---|
27 | */
|
---|
28 |
|
---|
29 | const trunc = isFunction(Math.trunc)
|
---|
30 | ? curryN(1, bind(Math.trunc, Math))
|
---|
31 | : truncPonyfill;
|
---|
32 |
|
---|
33 | export default trunc;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.