Skip to content

Commit abaed5c

Browse files
committed
Complettin of 2-practice-tdd
1 parent 6c49d14 commit abaed5c

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

Sprint-3/2-practice-tdd/count.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,28 @@ test("should count multiple occurrences of a character", () => {
2222
// And a character `char` that does not exist within `str`.
2323
// When the function is called with these inputs,
2424
// Then it should return 0, indicating that no occurrences of `char` were found.
25+
26+
function countChar(stringOfCharacters, findCharacter) {
27+
//return 5
28+
// function countChar(str, char) {
29+
let count = 0;
30+
31+
for (let i = 0; i < stringOfCharacters.length; i++) {
32+
if (stringOfCharacters[i] === char) {
33+
count++;
34+
}
35+
}
36+
37+
return count;
38+
}
39+
40+
41+
module.exports = countChar;
42+
43+
44+
test("should count multiple occurrences of a character", () => {
45+
const str = "aaaaa";
46+
const char = "a";
47+
const count = countCharA(str, char);
48+
expect(count).toEqual(5);
49+
});

Sprint-3/2-practice-tdd/get-ordinal-number.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,19 @@ test("should append 'st' for numbers ending with 1, except those ending with 11"
1818
expect(getOrdinalNumber(21)).toEqual("21st");
1919
expect(getOrdinalNumber(131)).toEqual("131st");
2020
});
21+
22+
function getOrdinalNumber(num) {
23+
nonStr = num.toString();
24+
if (nonStr.endsWith("1") && nonStr !== "11") {
25+
return nonStr.concat("st");
26+
} else if (nonStr.endsWith("2")) {
27+
return nonStr.concat("nd");
28+
} else if (nonStr.endsWith("3")) {
29+
return nonStr.concat("rd");
30+
} else {
31+
return "Invalid";
32+
}
33+
34+
}
35+
36+

Sprint-3/2-practice-tdd/repeat-str.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ test("should repeat the string count times", () => {
3030
// Given a target string `str` and a negative integer `count`,
3131
// When the repeatStr function is called with these inputs,
3232
// Then it should throw an error, as negative counts are not valid.
33+
34+
function repeatStr(str, count) {
35+
return str.repeat(count);
36+
}

0 commit comments

Comments
 (0)