|
|
@ -10,10 +10,30 @@ Create some functions which behave like JavaScript's `Math` rounding functions: |
|
|
|
- `trunc`: which behaves similar to `Math.trunc()`. |
|
|
|
- `trunc`: which behaves similar to `Math.trunc()`. |
|
|
|
|
|
|
|
|
|
|
|
> Some restrictions apply: |
|
|
|
> Some restrictions apply: |
|
|
|
|
|
|
|
> |
|
|
|
> - You may not use strings conversion to do it |
|
|
|
> - You may not use strings conversion to do it |
|
|
|
> - No bitwise operator |
|
|
|
> - No bitwise operator |
|
|
|
> - No `%` operator |
|
|
|
> - No `%` operator |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Usage |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```js |
|
|
|
|
|
|
|
const nums = [3.7, -3.7, 3.1, -3.1] |
|
|
|
|
|
|
|
console.log(nums.map(round)) |
|
|
|
|
|
|
|
console.log(nums.map(floor)) |
|
|
|
|
|
|
|
console.log(nums.map(trunc)) |
|
|
|
|
|
|
|
console.log(nums.map(ceil)) |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Output: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```console |
|
|
|
|
|
|
|
[ 4, -4, 3, -3 ] |
|
|
|
|
|
|
|
[ 3, -4, 3, -4 ] |
|
|
|
|
|
|
|
[ 3, -3, 3, -3 ] |
|
|
|
|
|
|
|
[ 4, -3, 4, -3 ] |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
### Notions |
|
|
|
### Notions |
|
|
|
|
|
|
|
|
|
|
|
- [Math](https://devdocs.io/javascript/global_objects/math) |
|
|
|
- [Math](https://devdocs.io/javascript/global_objects/math) |
|
|
|