Sheffield| 26-Jan-ITP| Mona-Eltantawy | Sprint 3| Sprint 3 /practice TDD#1282
Sheffield| 26-Jan-ITP| Mona-Eltantawy | Sprint 3| Sprint 3 /practice TDD#1282Mona-Eltantawy wants to merge 3 commits intoCodeYourFuture:mainfrom
Conversation
…e than 1, and to give empty out put for (0) and 'invalid count' output for negative counts.
cjyuan
left a comment
There was a problem hiding this comment.
In this exercise, you were expected to practice "Test Driven Development" (TDD) by
first preparing the Jest tests and then implement the function to pass the tests.
In particular, in the .test.js files, explain what behavior the function should exhibit in the following format:
should <expected_behavior> when <condition>
so that someone reading the test can understand the requirement without reading another spec.
| } | ||
|
|
||
| module.exports = countChar; | ||
| console.log(countChar('lol', 'l')); |
There was a problem hiding this comment.
When you are done testing the function, don't forget to remove all debugging code to keep the code clean.
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| function getOrdinalNumber(n) { | ||
| if (n % 100 >= 11 && n % 100 <= 13) return n + "th"; |
There was a problem hiding this comment.
Here is an alternative to express the code on line 2:
const lastTwoDigits = num % 100;
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) ...- More expressive
- Avoid evaluating the same expression multiple times
- (Cons) more code
Note: The difference might not be obvious in this example.
| function repeatStr(str, count) { | ||
| if( count >= 0 ) | ||
| {return str.repeat (count)}; | ||
| else { return 'invalid count'}; | ||
| }; |
There was a problem hiding this comment.
Indentation is off and some of the code is not consistently formatted.
Have you successfully assigned prettier as your default JS code formatter and enabled "Format on save/paste" on VSCode, as recommended in
https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/blob/main/readme.md
?
Self checklist