Skip to content

Commit 441d1bf

Browse files
committed
Refactor and merge if statements leading to the same result
1 parent 9633c24 commit 441d1bf

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

‎practice-tdd/get-ordinal-number.js‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,22 @@ export function getOrdinalNumber(num) {
33
throw new Error("Error: whole number is needed");
44
}
55

6-
if ((num - 11) % 100 === 0) {
6+
if (
7+
(num - 11) % 100 === 0 ||
8+
(num - 12) % 100 === 0 ||
9+
(num - 13) % 100 === 0
10+
) {
711
return num + "th";
812
}
913

1014
if ((num - 1) % 10 === 0) {
1115
return num + "st";
1216
}
1317

14-
if ((num - 12) % 100 === 0) {
15-
return num + "th";
16-
}
17-
1818
if ((num - 2) % 10 === 0) {
1919
return num + "nd";
2020
}
2121

22-
if ((num - 13) % 100 === 0) {
23-
return num + "th";
24-
}
25-
2622
if ((num - 3) % 10 === 0) {
2723
return num + "rd";
2824
}

0 commit comments

Comments
 (0)