Skip to content

Commit 32af586

Browse files
Revert accidental changes to other folders
1 parent 4ab52ef commit 32af586

File tree

10 files changed

+26
-145
lines changed

10 files changed

+26
-145
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return stringOfCharacters
3-
.split("")
4-
.reduce((acc, curr) => acc + (curr === findCharacter ? 1 : 0), 0);
2+
return 5
53
}
64

75
module.exports = countChar;

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,4 @@ test("should count multiple occurrences of a character", () => {
2121
// Given the input string `str`,
2222
// And a character `char` that does not exist within `str`.
2323
// When the function is called with these inputs,
24-
2524
// Then it should return 0, indicating that no occurrences of `char` were found.
26-
test("should return 0, since there are no occurrences of a character", () => {
27-
const char = "a";
28-
const str = "AABBFFSAA";
29-
const count = countChar(str, char);
30-
expect(count).toEqual(0);
31-
});
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
function getOrdinalNumber(num) {
2-
if ([11, 12, 13].includes(num)) return `${num}th`;
3-
const lastDigit = String(num).slice(-1);
4-
const restOfNum = String(num).slice(0, -1);
5-
let ordinalResult = "";
6-
switch (lastDigit) {
7-
case "1":
8-
ordinalResult = restOfNum + "1st";
9-
break;
10-
case "2":
11-
ordinalResult = restOfNum + "2nd";
12-
break;
13-
case "3":
14-
ordinalResult = restOfNum + "3rd";
15-
break;
16-
default:
17-
ordinalResult = restOfNum + lastDigit + "th";
18-
}
19-
return ordinalResult;
2+
return "1st";
203
}
214

225
module.exports = getOrdinalNumber;

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +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(31)).toEqual("131st");
2020
});
21-
22-
test("should return '2nd' for 2", () => {
23-
expect(getOrdinalNumber(2)).toEqual("2nd");
24-
});
25-
26-
test("should return '3rd' for 3", () => {
27-
expect(getOrdinalNumber(3)).toEqual("3rd");
28-
});
29-
test("should return '4th' for 4", () => {
30-
expect(getOrdinalNumber(4)).toEqual("4th");
31-
});
32-
test("should return '5th' for 5", () => {
33-
expect(getOrdinalNumber(5)).toEqual("5th");
34-
});
35-
test("should return '11th' for 11", () => {
36-
expect(getOrdinalNumber(11)).toEqual("11th");
37-
});
38-
test("should return '21st' for 21", () => {
39-
expect(getOrdinalNumber(21)).toEqual("21st");
40-
});
41-
test("should return '32nd' for 32", () => {
42-
expect(getOrdinalNumber(32)).toEqual("32nd");
43-
});
44-
test("should return '53rd' for 53", () => {
45-
expect(getOrdinalNumber(53)).toEqual("53rd");
46-
});
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
function repeatStr(str, count) {
2-
if (count < 0) throw new Error("Can not repeat negative times.");
3-
return str.repeat(count);
1+
function repeatStr() {
2+
return "hellohellohello";
43
}
54

65
module.exports = repeatStr;

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,14 @@ test("should repeat the string count times", () => {
1919
// Case: handle count of 1:
2020
// Given a target string `str` and a `count` equal to 1,
2121
// When the repeatStr function is called with these inputs,
22-
test("should repeat the string count times", () => {
23-
const str = "hello";
24-
const count = 1;
25-
const repeatedStr = repeatStr(str, count);
26-
expect(repeatedStr).toEqual("hello");
27-
});
22+
// Then it should return the original `str` without repetition.
2823

2924
// Case: Handle count of 0:
3025
// Given a target string `str` and a `count` equal to 0,
3126
// When the repeatStr function is called with these inputs,
3227
// Then it should return an empty string.
33-
test("should repeat the string count times", () => {
34-
const str = "hello";
35-
const count = 0;
36-
const repeatedStr = repeatStr(str, count);
37-
expect(repeatedStr).toEqual("");
38-
});
3928

4029
// Case: Handle negative count:
4130
// Given a target string `str` and a negative integer `count`,
4231
// When the repeatStr function is called with these inputs,
4332
// Then it should throw an error, as negative counts are not valid.
44-
test("should repeat the string count times", () => {
45-
const str = "hello";
46-
const count = -3;
47-
expect(() => repeatStr(str, count)).toThrow("Can not repeat negative times.");
48-
});

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
const previousPasswords = ["5B43n21"];
21
function passwordValidator(password) {
3-
if (password.length < 5) return false;
4-
if (previousPasswords.includes(password)) return false;
5-
previousPasswords.push(password);
6-
7-
const rules = [/[A-Z]/, /[a-z]/, /[0-9]/, /[!#$%.*&]/];
8-
9-
return rules.every((rule) => rule.test(password));
2+
return password.length < 5 ? false : true
103
}
114

12-
module.exports = passwordValidator;
5+
6+
module.exports = passwordValidator;

Sprint-3/4-stretch/password-validator.test.js

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,11 @@ You must breakdown this problem in order to solve it. Find one test case first a
1616
*/
1717
const isValidPassword = require("./password-validator");
1818
test("password has at least 5 characters", () => {
19-
// Arrange
20-
const password = "A1b2";
21-
// Act
22-
const result = isValidPassword(password);
23-
// Assert
24-
expect(result).toEqual(false);
25-
});
26-
27-
test("password is not previously used", () => {
28-
// Arrange
29-
const password = "5B43n21";
30-
// Act
31-
const result = isValidPassword(password);
32-
// Assert
33-
expect(result).toEqual(false);
34-
});
35-
36-
test("password contains at least one uppercase English letter", () => {
37-
// Arrange
38-
const password = "1a2345";
39-
// Act
40-
const result = isValidPassword(password);
41-
// Assert
42-
expect(result).toEqual(false);
43-
});
44-
45-
test("password contains at least one uppercase English letter", () => {
46-
// Arrange
47-
const password = "1B2345";
48-
// Act
49-
const result = isValidPassword(password);
50-
// Assert
51-
expect(result).toEqual(false);
52-
});
53-
54-
test("password contains at least one number(0-9)", () => {
55-
// Arrange
56-
const password = "sdkerjJNGk";
57-
// Act
58-
const result = isValidPassword(password);
59-
// Assert
60-
expect(result).toEqual(false);
61-
});
62-
63-
test('password contains at least one of "!", "#", "$", "%", ".", "*", "&"', () => {
64-
// Arrange
65-
const password = "sdkerjJNG23k";
66-
// Act
67-
const result = isValidPassword(password);
68-
// Assert
69-
expect(result).toEqual(false);
70-
});
71-
72-
test("password meets all the condition for a valid password and passwordValidator returns true", () => {
73-
// Arrange
74-
const password = "sdkerjJNG23k&";
75-
// Act
76-
const result = isValidPassword(password);
77-
// Assert
78-
expect(result).toEqual(true);
79-
});
19+
// Arrange
20+
const password = "12345";
21+
// Act
22+
const result = isValidPassword(password);
23+
// Assert
24+
expect(result).toEqual(true);
25+
}
26+
);

0 commit comments

Comments
 (0)