-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnum-romano.js
57 lines (46 loc) · 1.14 KB
/
num-romano.js
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
53
54
55
56
57
module.exports = function(RED) {
function NumRomano(config){
RED.nodes.createNode(this,config);
var node=this;
console.log("Inicializando.....");
node.on('input',function(msg){
msg.payload = convertirRomano(parseInt(msg.payload),config);
if (config.config==true){
msg.config = config;
}
node.send(msg);
});
node.on('close',function (){
console.log("Cerrando.....");
});
}
RED.nodes.registerType("num-romano",NumRomano);
}
function convertirRomano(num,kk){
var conversion = {
M:1000,
CM:900,
D:500,
CD:400,
C:100,
XC:90,
L:50,
XL:40,
X:10,
IX:9,
V:5,
IV:4,
I:1
};
var romano = '';
for(i in conversion){
while(num >= conversion[i]){
romano += i;
num -= conversion[i];
}
}
return romano;
}
/* for(j=1;j<101;j++){
console.log("El número "+ j + " en romano es: "+convertirRomano(j));
} */