-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata.js
49 lines (35 loc) · 1 KB
/
kata.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
function solution(number) {
const roNums = {
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,
};
let str = '';
for (let i of Object.keys(roNums)) {
let q = Math.floor(number / roNums[i]);
number -= q * roNums[i];
str += i.repeat(q);
}
return str;
}
console.log(solution(1));
// 'I', '1 should return "I"'
console.log(solution(2));
// 'II', '2 should return "II"'
console.log(solution(3));
// 'III', '3 should return "III"'
console.log(solution(4));
// 'IV', '4 should return "IV"'
console.log(solution(5));
// 'V', '5 should return "V"'
console.log(solution(9));
// 'IX', '9 should return "IX"'
console.log(solution(10));
// 'X', '10 should return "X"'
console.log(solution(11));
// 'XI', '11 should return "XI"'
console.log(solution(19));
// 'XIX', '19 should return "XIX"'
console.log(solution(22));
// 'XXII', '22 should return "XXII"'
console.log(solution(15));
// 'XV', '15 should return "XV"'