-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArith.js
78 lines (70 loc) · 1.58 KB
/
Arith.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
74
75
76
77
78
// This is the first part of this kata series. Second part is here and third part is here
// Add two English words together!
// Implement a class Arith (struct struct Arith{value : &'static str,} in Rust) such that
// //javascript
// var k = new Arith("three");
// k.add("seven"); //this should return "ten"
// Input - Will be between zero and ten and will always be in lower case
// Output - Word representation of the result of the addition. Should be in lower case
class Arith {
constructor(value) {
this.value = value;
}
mapToNum(value) {
const numbers = {
zero: 0,
one: 1,
two: 2,
three: 3,
four: 4,
five: 5,
six: 6,
seven: 7,
eight: 8,
nine: 9,
ten: 10,
eleven: 11,
twelve: 12,
thirteen: 13,
fourteen: 14,
fifteen: 15,
sixteen: 16,
seventeen: 17,
eighteen: 18,
nineteen: 19,
twenty: 20,
};
console.log(numbers[value]);
return numbers[value];
}
mapToStr(value) {
const words = {
0: "zero",
1: "one",
2: "two",
3: "three",
4: "four",
5: "five",
6: "six",
7: "seven",
8: "eight",
9: "nine",
10: "ten",
11: "eleven",
12: "twelve",
13: "thirteen",
14: "fourteen",
15: "fifteen",
16: "sixteen",
17: "seventeen",
18: "eighteen",
19: "nineteen",
20: "twenty",
};
return words[value];
}
add(nextValue) {
const sum = this.mapToNum(this.value) + this.mapToNum(nextValue);
return this.mapToStr(sum);
}
}