Repository navigation
London | 26 ITP MAY | Russom Gebremeskel | Sprint 1 | Dead Code #1632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
301ea63
2501561
63e477b
a8e1b2d
9e2cef8
2ba2e34
06d5f91
3dc6da6
1e6cb55
61b2ce7
0407869
06d3f9a
598f744
e6fde3b
c2f743c
e7ff9c7
751fb78
4707f5a
f504687
d9197c4
9494c3d
582699c
b806b41
fcf27e7
04f544f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,6 @@ | ||
| // Find the instances of unreachable and redundant code - remove them! | ||
| // The sayHello function should continue to work for any reasonable input it's given. | ||
|
|
||
| let testName = "Jerry"; | ||
| const greeting = "hello"; | ||
|
|
||
| function sayHello(greeting, name) { | ||
| const greetingStr = greeting + ", " + name + "!"; | ||
| return `${greeting}, ${name}!`; | ||
| console.log(greetingStr); | ||
| } | ||
|
|
||
| testName = "Aman"; | ||
|
|
||
| const greetingMessage = sayHello(greeting, testName); | ||
|
|
||
| console.log(greetingMessage); // 'hello, Aman!' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,27 +2,24 @@ | |
| // 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"]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is |
||
| 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 = {}; | ||
|
|
||
| petsArr.forEach((pet) => { | ||
| const capitalisedPet = pet.toUpperCase(); | ||
| if (petCount[capitalisedPet]) { | ||
| petCount[capitalisedPet] += 1; | ||
| } else { | ||
| petCount[capitalisedPet] = 1; | ||
| } | ||
| }); | ||
| petsArr | ||
| .filter((pet) => pet[0] === "h") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment on line 2 says this function should keep working for any reasonable input. What does |
||
| .forEach((pet) => { | ||
| const capitalisedPet = pet.toUpperCase(); | ||
|
|
||
| if (petCount[capitalisedPet]) { | ||
| petCount[capitalisedPet] += 1; | ||
| } else { | ||
| petCount[capitalisedPet] = 1; | ||
| } | ||
| }); | ||
|
|
||
| return petCount; | ||
| } | ||
|
|
||
| const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); | ||
|
|
||
| console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log | ||
| const animals = ["lion", "hyena", "elephant", "hippo", "tiger", "hippo"]; | ||
| console.log(countAndCapitalisePets(animals)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The starter's final log printed |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run
node dead-code/exercise-1.jsonmainand on your branch. What does each print? Dead code is code that never affects the output, so wasconsole.log(greetingMessage)dead?