This repository was archived by the owner on Apr 18, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathget-ordinal-number.test.js
More file actions
58 lines (46 loc) · 1.53 KB
/
get-ordinal-number.test.js
File metadata and controls
58 lines (46 loc) · 1.53 KB
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
// In this week's prep, we started implementing getOrdinalNumber
// continue testing and implementing getOrdinalNumber for additional cases
// Write your tests using Jest - remember to run your tests often for continual feedback
function getOrdinalNumber(number) {
const lastNum = number.toString().slice(-1);
if (lastNum === "1") {
return number + "st";
} else if (lastNum === "2") {
return number + "nd";
} else if (lastNum === "3") {
return number + "rd";
} else {
return number + "th";
}
return lastNum;
}
test("converts 1 to an ordinal number", function () {
const input = 1;
const currentOutput = getOrdinalNumber(input);
const targetOutput = "1st";
expect(currentOutput).toBe(targetOutput);
});
test("converts 10 to an ordinal number", function () {
const input = 10;
const currentOutput = getOrdinalNumber(input);
const targetOutput = "10th";
expect(currentOutput).toBe(targetOutput);
});
test("converts 22 to an ordinal number", function () {
const input = 22;
const currentOutput = getOrdinalNumber(input);
const targetOutput = "22nd";
expect(currentOutput).toBe(targetOutput);
});
test("converts 33 to an ordinal number", function () {
const input = 33;
const currentOutput = getOrdinalNumber(input);
const targetOutput = "33rd";
expect(currentOutput).toBe(targetOutput);
});
test("converts 45 to an ordinal number", function () {
const input = 45;
const currentOutput = getOrdinalNumber(input);
const targetOutput = "45th";
expect(currentOutput).toBe(targetOutput);
});