diff --git a/Sprint-3/2-practice-tdd/count.js b/Sprint-3/2-practice-tdd/count.js index 95b6ebb7d..a7310ad34 100644 --- a/Sprint-3/2-practice-tdd/count.js +++ b/Sprint-3/2-practice-tdd/count.js @@ -1,5 +1,8 @@ -function countChar(stringOfCharacters, findCharacter) { - return 5 +function countChar(str, char) { + + return str.split(char).length -1; } -module.exports = countChar; +console.log(countChar('lol', 'l')); + +module.exports = countChar; \ No newline at end of file diff --git a/Sprint-3/2-practice-tdd/get-ordinal-number.js b/Sprint-3/2-practice-tdd/get-ordinal-number.js index f95d71db1..8613add93 100644 --- a/Sprint-3/2-practice-tdd/get-ordinal-number.js +++ b/Sprint-3/2-practice-tdd/get-ordinal-number.js @@ -1,5 +1,11 @@ -function getOrdinalNumber(num) { - return "1st"; +function getOrdinalNumber(n) { + if (n % 100 >= 11 && n % 100 <= 13) return n + "th"; + + if (n % 10 === 1) return n + "st"; + if (n % 10 === 2) return n + "nd"; + if (n % 10 === 3) return n + "rd"; + + return n + "th"; } module.exports = getOrdinalNumber; diff --git a/Sprint-3/2-practice-tdd/repeat-str.js b/Sprint-3/2-practice-tdd/repeat-str.js index 3838c7b00..e74db07ce 100644 --- a/Sprint-3/2-practice-tdd/repeat-str.js +++ b/Sprint-3/2-practice-tdd/repeat-str.js @@ -1,5 +1,7 @@ -function repeatStr() { - return "hellohellohello"; -} +function repeatStr(str, count) { + if( count >= 0 ) + {return str.repeat (count)}; +else { return 'invalid count'}; +}; module.exports = repeatStr; diff --git a/Sprint-3/3-dead-code/exercise-1.js b/Sprint-3/3-dead-code/exercise-1.js index 4d09f15fa..2425c454d 100644 --- a/Sprint-3/3-dead-code/exercise-1.js +++ b/Sprint-3/3-dead-code/exercise-1.js @@ -10,8 +10,4 @@ function sayHello(greeting, name) { console.log(greetingStr); } -testName = "Aman"; - -const greetingMessage = sayHello(greeting, testName); - -console.log(greetingMessage); // 'hello, Aman!' +testName = "Aman"; \ No newline at end of file diff --git a/Sprint-3/3-dead-code/exercise-2.js b/Sprint-3/3-dead-code/exercise-2.js index 56d7887c4..b1c2362d3 100644 --- a/Sprint-3/3-dead-code/exercise-2.js +++ b/Sprint-3/3-dead-code/exercise-2.js @@ -2,13 +2,8 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -const capitalisedPets = pets.map((pet) => pet.toUpperCase()); const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} - function countAndCapitalisePets(petsArr) { const petCount = {};