Skip to content

Commit

Permalink
Add solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylagordon committed Mar 21, 2024
1 parent 2884dec commit 30747a2
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lessons/module-2/approaching-problems-many-ways.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ Expect output => `[ 'Tamagotchi', 'Super Soaker', 'Pogs' ]`
### Round 1: `forEach`
- Solve the prompt using a `forEach`. You may not use any other iterator methods.

<section class="answer">
### Round 1 Sample Solution (don't peek!)

```js
function findCheapToys() {
let cheapToyNames = [];

ninetiesToys.forEach(toy => {
if (toy.price < 20) {
cheapToyNames.push(toy.name)
}
});

return cheapToyNames;
}
```
</section>

<section class="call-to-action">
### Round 1 Reflection

Expand All @@ -66,6 +84,19 @@ Expect output => `[ 'Tamagotchi', 'Super Soaker', 'Pogs' ]`
### Round 2: `filter` and `map`
- Solve the prompt using a `filter` and `map`. You may not use any other iterator methods.

<section class="answer">
### Round 2 Sample Solution (don't peek!)

```js
function findCheapToys() {
let cheapToys = ninetiesToys.filter(toy => toy.price < 20);
let cheapToyNames = cheapToys.map(toy => toy.name);

return cheapToyNames;
}
```
</section>

<section class="call-to-action">
### Round 2 Reflection

Expand All @@ -76,6 +107,21 @@ Expect output => `[ 'Tamagotchi', 'Super Soaker', 'Pogs' ]`
### Round 3: `reduce`
- Solve the prompt using a `reduce`. You may not use any other iterator methods.

<section class="answer">
### Round 3 Sample Solution (don't peek!)

```js
function findCheapToys() {
return ninetiesToys.reduce((cheapToyNames, toy) => {
if (toy.price < 20) {
cheapToyNames.push(toy.name);
}
return cheapToyNames;
}, []);
}
```
</section>

<section class="call-to-action">
### Round 3 Reflection

Expand Down

0 comments on commit 30747a2

Please sign in to comment.