-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath_utils.js
More file actions
52 lines (45 loc) · 1.24 KB
/
math_utils.js
File metadata and controls
52 lines (45 loc) · 1.24 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// @ts-nocheck
/* eslint-disable */
/**
* @file With various utility and helper functionality
* @author Jonas Brandel
*/
/** lib_version = Current version of this file
* @constant
@type {number}
@default
*/
const lib_version = 1;
/**
* Function that tells if a integer is an even number
* @example
* // returns true
* isEven(22);
* @param {number} number - An integer number to check if number is even
*/
function isEven(number){
//We expect a integer number
if(!(typeof number == typeof 0
&& Number.isInteger(number))) //ES6
{
throw "Not a number";
}
// It would be enough to check if the least significant bit is 0 to mean
// it is divisable by 2, but probably doesnt matter
//For now we use modulo 2, and check that there is no remainder
return number % 2 == 0;
}
/**
* Function that tells if a integer is an odd number
* @example
* // returns false
* isEven(22);
* @param {number} number - An integer number to check if number is odd
*/
function isOdd (number){
//TODO - This should use an expression instead of invoking a function, which has a higher cost!
return !isEven(number);
}
console.log(isEven(148));
console.log(isOdd(155));
console.log(isEven("Four"));