Merge remote-tracking branch 'origin/master'

This commit is contained in:
Angelos Chalaris
2018-01-08 17:24:29 +02:00
2 changed files with 31 additions and 1 deletions

View File

@ -237,6 +237,7 @@ average(1, 2, 3);
* [`standardDeviation`](#standarddeviation)
* [`sum`](#sum)
* [`sumPower`](#sumpower)
* [`toSafeInteger`](#tosafeinteger)
</details>
@ -3468,6 +3469,31 @@ sumPower(10, 3, 5); //2925
<br>[⬆ Back to top](#table-of-contents)
### toSafeInteger
Converts a value to a safe integer.
Use `Math.max()` and `Math.min()` to find the closest safe value.
Use `Math.round()` to convert to an integer.
```js
const toSafeInteger = num =>
Math.round(Math.max(Math.min(num, Number.MAX_SAFE_INTEGER), Number.MIN_SAFE_INTEGER));
```
<details>
<summary>Examples</summary>
```js
toSafeInteger('3.2'); // 3
toSafeInteger(Infinity); // 9007199254740991
```
</details>
<br>[⬆ Back to top](#table-of-contents)
---
## 📦 Node

File diff suppressed because one or more lines are too long