Skip to content

Commit 29c19f6

Browse files
committed
Exercises 5-7 source refactored
3 more down. I think.
1 parent 12e8494 commit 29c19f6

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

exercises/05 - Flex Panel Gallery/index.html

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
43
<head>
54
<meta charset="UTF-8">
65
<title>Flex Panels 💪</title>
@@ -27,29 +26,26 @@
2726
.panel1 {
2827
background-image: url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500);
2928
}
30-
29+
3130
.panel2 {
3231
background-image: url(https://source.unsplash.com/1CD3fd8kHnE/1500x1500);
3332
}
34-
33+
3534
.panel3 {
3635
background-image: url(https://images.unsplash.com/photo-1465188162913-8fb5709d6d57?ixlib=rb-0.3.5&q=80&fm=jpg&crop=faces&cs=tinysrgb&w=1500&h=1500&fit=crop&s=967e8a713a4e395260793fc8c802901d);
3736
}
38-
37+
3938
.panel4 {
4039
background-image: url(https://source.unsplash.com/ITjiVXcwVng/1500x1500);
4140
}
42-
41+
4342
.panel5 {
4443
background-image: url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500);
4544
}
4645
</style>
47-
4846
</head>
49-
5047
<body>
5148

52-
5349
<div class="panels">
5450
<div class="panel panel1">
5551
<p>Hey</p>
@@ -81,20 +77,18 @@
8177
<script>
8278
const panels = document.querySelectorAll('.panel')
8379

84-
function togglePanel() {
85-
this.classList.toggle('open');
80+
const togglePanel = (p, e) => {
81+
p.classList.toggle('open');
8682
}
8783

88-
function toggleText(e) {
89-
if (e.propertyName.includes('flex')) this.classList.toggle('open-active');
84+
const toggleText = (p, e) => {
85+
if (e.propertyName.includes('flex')) p.classList.toggle('open-active');
9086
}
9187

92-
panels.forEach(panel => panel.addEventListener('click', togglePanel));
93-
panels.forEach(panel => panel.addEventListener('transitionend', toggleText));
88+
panels.forEach(panel => {
89+
panel.addEventListener('click', togglePanel.bind(null, panel))
90+
panel.addEventListener('transitionend', toggleText.bind(null, panel))
91+
})
9492
</script>
95-
96-
97-
9893
</body>
99-
100-
</html>
94+
</html>

exercises/06 - Type Ahead/index.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131
.then(data => cities.push(...data))
3232

3333
// Step 4
34-
const matchInput = (inputString, cities) => cities.filter((location) => {
35-
const regex = new RegExp(inputString, 'gi');
36-
return location.city.match(regex) || location.state.match(regex)
37-
});
34+
const matchInput = (inputString, cities) => cities.filter(({city, state}) => (
35+
city.match(new RegExp(inputString, 'gi')) || state.match(new RegExp(inputString, 'gi'))
36+
));
3837

3938
// Step 6
4039
const numberWithCommas = (x) => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');

exercises/07 - Array Cardio Day 2/index.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,33 @@
2525
{ text: 'Nice Nice Nice!', id: 542328 }
2626
];
2727

28+
const yr = new Date().getFullYear();
2829
// Some and Every Checks
29-
// Array.prototype.some()
30+
// Array.prototype.some()
3031
// is at least one person 19?
31-
const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19);
32+
const isAdult = people.some(({year}) => yr - year >= 19);
3233
console.log({ isAdult });
3334

3435
// Array.prototype.every() // is everyone 19?
35-
const allAdults = people.every(person => ((new Date()).getFullYear()) - person.year >= 19);
36+
const allAdults = people.every(({year}) => yr - year >= 19);
3637
console.log({ allAdults });
3738

3839
// Array.prototype.find()
3940
// Find is like filter, but instead returns just the one you are looking for
4041
// find the comment with the ID of 823423
41-
const comment = comments.find(comment => comment.id === 823423);
42+
const comment = comments.find(({id}) => id === 823423);
4243
console.log(comment);
4344

4445
// Array.prototype.findIndex()
4546
// Find the comment with this ID 823423 and delete it
46-
const index = comments.findIndex(comment => comment.id === 823423);
47+
const index = comments.findIndex(({id}) => id === 823423);
4748
const newComments = [
4849
...comments.slice(0, index),
4950
...comments.slice(index + 1)
5051
];
51-
console.log(newComments)
52+
console.table(newComments)
5253

5354
</script>
5455
</body>
5556

56-
</html>
57+
</html>

0 commit comments

Comments
 (0)