forked from davidmillercode/JavaScript-Problem-Solving
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateMathMethods.js
More file actions
29 lines (25 loc) · 765 Bytes
/
Copy pathcreateMathMethods.js
File metadata and controls
29 lines (25 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Created by D on 3/4/2015.
*/
/*
Oh no, our Math object was "accidently" reset. Can you re-implement some of those functions? We can assure, that only
non-negative numbers are passed as arguments. So you don't have to consider things like undefined, null, NaN, negative
numbers, strings and so on.
Here is a list of functions, we need:
Math.round()
Math.ceil()
Math.floor()
*/
Math.round = function(number) {
var difference = number - (number | 0);
if (difference >= .5) return number + 1 | 0;
return number | 0;
};
Math.ceil = function(number) { //goes up
var difference = number % 1;
if (difference !== 0) return number + 1 | 0;
return number; //if already int
};
Math.floor = function(number) {
return number | 0;
};