-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword2number.js
executable file
·73 lines (69 loc) · 1.79 KB
/
word2number.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Word2Number
* Author: Karim Saad
* Month/Year: 08/2019
*/
const replaceString = require('replace-string');
const word2Number = function (inp) {
data = {
"eins": 1,
"zwei": 2,
"drei": 3,
"vier": 4,
"fünf": 5,
"sechs": 6,
"sieben": 7,
"acht": 8,
"neun": 9,
"zehn": 10,
"zwan": 2,
"ein": 1,
"eine": 1,
"einen": 1
}
for (var i=0; i < 10000; i++ ) {
data[i] = i;
}
var nstr = "";
if(inp.includes(" und ")) {
if (inp.includes("zig")){
var spl = inp.split(" ");
spl = spl.reverse();
spl.forEach(function(el){
if(el.includes("zig")) {
var nx= replaceString(el, "zig","");
nstr += data[nx];
}
if(data[el] != null && data[el] != undefined && el != "und") {
nstr += data[el];
}
});
}
} else {
if (inp.includes("zig")){
var spl = inp.split(" ");
var cintzigs = 0;
spl = spl.reverse();
spl.forEach(function(el){
if(el.includes("zig")) {
cintzigs++;
var nx= replaceString(el, "zig","");
nstr += data[nx];
}
if(data[el] != null) {
nstr += data[el];
}
});
if(cintzigs == 1)nstr += "0";
} else {
var spl = inp.split(" ");
spl.forEach(function(el){
if(data[el] != null) {
nstr += data[el];
}
});
}
}
return parseInt(nstr);
}
module.exports = word2Number;