Skip to content

Commit 1430fe4

Browse files
author
Arthur
committed
Submit practice-tdd exercise cleanly
1 parent b31a586 commit 1430fe4

6 files changed

Lines changed: 56 additions & 5 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
let count=0;
3+
for(let letter of stringOfCharacters)
4+
{if(letter=== findCharacter){
5+
count= count+1;
6+
}
7+
}
8+
return count;
39
}
410

511
module.exports = countChar;
12+
13+
//For committing//

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ 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+
//for committing//
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
3+
if(num===11){
4+
return num + "th";
5+
}
6+
if(num%10===1){
7+
return num + "st";
8+
}
9+
10+
if(num%10===2){
11+
return num +"nd";
12+
}
13+
14+
if(num%10===3){
15+
return num +"rd";
16+
}
317
}
418

519
module.exports = getOrdinalNumber;
20+
21+
22+
23+
24+
25+
26+
27+
//for committing//

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ 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+
//for committing//
Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
function repeatStr() {
1+
function repeatStr(str, count) {
22
// 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).
33
// The goal is to re-implement that function, not to use it.
4-
return "hellohellohello";
5-
}
4+
let repeatedStr= "";
5+
6+
for(i=0; i<count; i++){
7+
repeatedStr= repeatedStr + str;
8+
};
9+
return repeatedStr;}
10+
11+
12+
613

714
module.exports = repeatStr;
15+
16+
17+
18+
19+
20+
21+
22+
//for committing//

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ test("should repeat the string count times", () => {
3030
// Given a target string `str` and a negative integer `count`,
3131
// When the repeatStr function is called with these inputs,
3232
// Then it should throw an error, as negative counts are not valid.
33+
34+
//for committing//

0 commit comments

Comments
 (0)