Skip to content

Commit 46adf4d

Browse files
author
Arthur
committed
Dead code refactoring
1 parent e0aa9aa commit 46adf4d

4 files changed

Lines changed: 34 additions & 13 deletions

File tree

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
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+

Sprint-3/3-dead-code/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Here are two example of code that has not been built efficiently. Both files hav
66

77
1. Work through each `exercise` file inside this directory.
88
2. Delete the dead code.
9-
3. Commit your changes and make a PR when done.
9+
3. Commit your changes and make a PR when done.

Sprint-3/3-dead-code/exercise-1.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
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 = "Jerry";
4+
let testName = "Aman";
55
const greeting = "hello";
66

77
function sayHello(greeting, name) {
8-
const greetingStr = greeting + ", " + name + "!";
98
return `${greeting}, ${name}!`;
10-
console.log(greetingStr);
119
}
1210

13-
testName = "Aman";
14-
1511
const greetingMessage = sayHello(greeting, testName);
1612

1713
console.log(greetingMessage); // 'hello, Aman!'
14+
15+
16+
17+
18+
19+

Sprint-3/3-dead-code/exercise-2.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
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());
65
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");
76

8-
function logPets(petsArr) {
9-
petsArr.forEach((pet) => console.log(pet));
10-
}
117

128
function countAndCapitalisePets(petsArr) {
139
const petCount = {};
@@ -26,3 +22,13 @@ function countAndCapitalisePets(petsArr) {
2622
const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH);
2723

2824
console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+

0 commit comments

Comments
 (0)