Visitar URL original
Day 7. · wesbos/JavaScript30@58f948b · GitHub
Skip to content

Commit 58f948b

Browse files
committed
Day 7.
1 parent 356760e commit 58f948b

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎07 - Array Cardio Day 2/data.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const people = [
2+
{ name: 'Wes', year: 1988 },
3+
{ name: 'Kait', year: 1986 },
4+
{ name: 'Irv', year: 1970 },
5+
{ name: 'Lux', year: 2015 }
6+
];
7+
8+
const comments = [
9+
{ text: 'Love this!', id: 523423 },
10+
{ text: 'Super good', id: 823423 },
11+
{ text: 'You are the best', id: 2039842 },
12+
{ text: 'Ramen is my fav food ever', id: 123523 },
13+
{ text: 'Nice Nice Nice!', id: 542328 }
14+
];

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Array Cardio 💪💪</title>
6+
<script src="data.js"></script>
7+
</head>
8+
<body>
9+
10+
<p><em>Psst: have a look at the JavaScript Console</em> 💁</p>
11+
12+
<script>
13+
// Some and Every Checks
14+
const thisYear = ( new Date() ).getFullYear();
15+
const isNineteenOrOlder = ( { year } ) => ( 19 <= thisYear - year );
16+
17+
// Array.prototype.some() // is at least one person 19 or older?
18+
console.log( people.some( isNineteenOrOlder ) );
19+
20+
// Array.prototype.every() // is everyone 19 or older?
21+
console.log( people.every( isNineteenOrOlder ) );
22+
23+
// Array.prototype.find()
24+
// Find is like filter, but instead returns just the one you are looking for
25+
// find the comment with the ID of 823423
26+
console.log( comments.find( ( { id } ) => ( 823423 === id ) ) );
27+
28+
// Array.prototype.findIndex()
29+
// Find the comment with this ID
30+
const index = comments.findIndex( ( { id } ) => ( 823423 === id ) );
31+
32+
console.log( comments[ index ] );
33+
34+
// delete the comment with the ID of 823423
35+
comments.splice( index, 1 );
36+
37+
console.log( comments );
38+
</script>
39+
40+
</body>
41+
</html>

0 commit comments

Comments
 (0)