Skip to content

Commit b441617

Browse files
committed
Ex7 - Array cardio day 2
1 parent 5691666 commit b441617

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

07 - Array Cardio Day 2/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
<script src="script.js" charset="utf-8"></script>
9+
</body>
10+
</html>

07 - Array Cardio Day 2/script.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
const people = [
4+
{ name: 'Wes', year: 1988 },
5+
{ name: 'Kait', year: 1986 },
6+
{ name: 'Irv', year: 1970 },
7+
{ name: 'Lux', year: 2015 }
8+
];
9+
10+
const comments = [
11+
{ text: 'Love this!', id: 523423 },
12+
{ text: 'Super good', id: 823423 },
13+
{ text: 'You are the best', id: 2039842 },
14+
{ text: 'Ramen in my fav food ever', id: 123523 },
15+
{ text: 'Nice Nice Nice!', id: 542328 }
16+
];
17+
18+
const isAdult = people.some(adult => new Date().getFullYear() - adult.year >= 19);
19+
console.log(isAdult);
20+
21+
const allAdults = people.every(adult => new Date().getFullYear() - adult.year >= 19);
22+
console.log(allAdults);
23+
24+
25+
//Find the comment with the id of 823423
26+
const comment = comments.find(c => c.id === 823423);
27+
console.log(comment.text);
28+
29+
const index = comments.findIndex(c => c.id === 823423);
30+
31+
// normal way
32+
comments.splice(index, 1);
33+
console.log(comments);
34+
35+
//redux way ?
36+
// const newArray = [
37+
// ...comments.slice(0, index),
38+
// ...comments.slice(index + 1)
39+
// ];
40+
// console.log(newArray);

0 commit comments

Comments
 (0)