Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Sprint-3/2-practice-tdd/count.js
Original file line number Diff line number Diff line change
@@ -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'));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you are done testing the function, don't forget to remove all debugging code to keep the code clean.


module.exports = countChar;
12 changes: 9 additions & 3 deletions Sprint-3/2-practice-tdd/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function getOrdinalNumber(num) {
return "1st";
function getOrdinalNumber(n) {
if (n % 100 >= 11 && n % 100 <= 13) return n + "th";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


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;
module.exports = getOrdinalNumber;
10 changes: 6 additions & 4 deletions Sprint-3/2-practice-tdd/repeat-str.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function repeatStr() {
return "hellohellohello";
}
function repeatStr(str, count) {
if( count >= 0 )
{return str.repeat (count)};
else { return 'invalid count'};
};
Comment on lines +1 to +5
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
?


module.exports = repeatStr;
module.exports = repeatStr;
Loading