forked from elixirscript/elixirscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteger.js
More file actions
38 lines (27 loc) · 697 Bytes
/
integer.js
File metadata and controls
38 lines (27 loc) · 697 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
30
31
32
33
34
35
36
37
38
import Kernel from './kernel';
let Integer = {
is_even: function(n){
return n % 2 === 0;
},
is_odd: function(n){
return n % 2 !== 0;
},
parse: function(bin){
let result = parseInt(bin);
if(isNaN(result)){
return Kernel.SpecialForms.atom("error");
}
let indexOfDot = bin.indexOf(".");
if(indexOfDot >= 0){
return Kernel.SpecialForms.tuple(result, bin.substring(indexOfDot));
}
return Kernel.SpecialForms.tuple(result, "");
},
to_char_list: function(number, base = 10){
return number.toString(base).split('');
},
to_string: function(number, base = 10){
return number.toString(base);
}
};
export default Integer;