mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
miguel
446966c564
|
2 years ago | |
---|---|---|
.. | ||
README.md | 2 years ago |
README.md
Cut Corners
Instructions
Create some functions which behave like JavaScript's Math
rounding functions:
round
: which behaves similar toMath.round()
.ceil
: which behaves similar toMath.ceil()
.floor
: which behaves similar toMath.floor()
.trunc
: which behaves similar toMath.trunc()
.
Some restrictions apply:
- You may not use strings conversion to do it
- No bitwise operator
- No
%
operator
Usage
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:
[ 4, -4, 3, -3 ]
[ 3, -4, 3, -4 ]
[ 3, -3, 3, -3 ]
[ 4, -3, 4, -3 ]
Notions
Code provided
The provided code will be added to your solution, and does not need to be submitted.
Math.round = Math.ceil = Math.floor = Math.trunc = undefined