Skip to content

Commit 6e8feda

Browse files
author
JorvanW
committed
Updated sprint for PR
1 parent 919dba4 commit 6e8feda

8 files changed

Lines changed: 17 additions & 72 deletions

File tree

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
let count = 0
3-
for (const char of stringOfCharacters) {
4-
if (char === findCharacter) {
5-
count++
6-
}
7-
}
8-
return count
2+
return 5
93
}
104

115
module.exports = countChar;

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,3 @@ 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-
test("should return 0 when character is not found", () => {
27-
const str = "hello";
28-
const char = "z";
29-
const count = countChar(str, char);
30-
expect(count).toEqual(0);
31-
});
32-
33-
test("should return the number of occurrences of a character in a string with different characters", () => {
34-
const str = "london";
35-
const char = "o";
36-
const count = countChar(str, char);
37-
expect(count).toEqual(2);
38-
});
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
function getOrdinalNumber(num) {
2-
if (num % 100 === 11) {
3-
return num + "th";
4-
} else if (num % 10 === 1) {
5-
return num + "st";
6-
} else {
7-
return num
8-
}
2+
return "1st";
93
}
104

115
module.exports = getOrdinalNumber;

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,3 @@ 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-
// Case 2: Numbers ending with 11
23-
test("should append 'th' for numbers ending with 11", () => {
24-
expect(getOrdinalNumber(11)).toEqual("11th");
25-
expect(getOrdinalNumber(111)).toEqual("111th");
26-
expect(getOrdinalNumber(211)).toEqual("211th");
27-
});
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
function repeatStr(str, times) {
2-
if (times === 0) {
3-
return "";
4-
} else if (times < 0) {
5-
throw new Error("error");
6-
}
7-
8-
let repeatedString = "";
9-
for (let i = 0; i < times; i++) {
10-
repeatedString += str;
11-
}
12-
return repeatedString;
13-
}
1+
function repeatStr() {
2+
// Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat).
3+
// The goal is to re-implement that function, not to use it.
4+
return "hellohellohello";
5+
}
146

157
module.exports = repeatStr;

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,12 @@ test("should repeat the string count times", () => {
2121
// When the repeatStr function is called with these inputs,
2222
// Then it should return the original `str` without repetition.
2323

24-
test("should return the original string when count is 1", () => {
25-
const str = "world";
26-
const count = 1;
27-
const repeatedStr = repeatStr(str, count);
28-
expect(repeatedStr).toEqual("world");
29-
});
30-
3124
// Case: Handle count of 0:
3225
// Given a target string `str` and a `count` equal to 0,
3326
// When the repeatStr function is called with these inputs,
3427
// Then it should return an empty string.
3528

36-
test("should return an empty string when count is 0", () => {
37-
const str = "world";
38-
const count = 0;
39-
const repeatedStr = repeatStr(str, count);
40-
expect(repeatedStr).toEqual("");
41-
});
42-
4329
// Case: Handle negative count:
4430
// Given a target string `str` and a negative integer `count`,
4531
// When the repeatStr function is called with these inputs,
4632
// Then it should throw an error, as negative counts are not valid.
47-
48-
test("should throw an error when count is negative", () => {
49-
const str = "world";
50-
const count = -1;
51-
52-
expect(() => {
53-
repeatStr(str, count);
54-
}).toThrow("error");
55-
});

Sprint-3/3-dead-code/exercise-1.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// Find the instances of unreachable and redundant code - remove them!
22
// The sayHello function should continue to work for any reasonable input it's given.
33

4-
let testName = "Aman";
4+
let testName = "Jerry";
55
const greeting = "hello";
66

77
function sayHello(greeting, name) {
8+
const greetingStr = greeting + ", " + name + "!";
89
return `${greeting}, ${name}!`;
10+
console.log(greetingStr);
911
}
1012

13+
testName = "Aman";
14+
1115
const greetingMessage = sayHello(greeting, testName);
1216

1317
console.log(greetingMessage); // 'hello, Aman!'

Sprint-3/3-dead-code/exercise-2.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable.
33

44
const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"];
5+
const capitalisedPets = pets.map((pet) => pet.toUpperCase());
56
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");
67

8+
function logPets(petsArr) {
9+
petsArr.forEach((pet) => console.log(pet));
10+
}
11+
712
function countAndCapitalisePets(petsArr) {
813
const petCount = {};
914

0 commit comments

Comments
 (0)