Skip to content

Commit a18d311

Browse files
committed
Completed project 6
1 parent bcbab53 commit a18d311

File tree

4 files changed

+101
-33
lines changed

4 files changed

+101
-33
lines changed

06 - Type Ahead/typescripts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Concepts: AJAX, Fetch API
66
* Key takeaways: Get the data first, then worry about displaying it.
77
* Sidenotes:
8-
* Fetch API uses Promises.
8+
* Fetch API uses Promises, but --target es5 does not cause errors...
99
* I've no idea how that comma adding regexp works...
1010
*/
1111

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,14 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>Array Cardio 💪💪</title>
67
</head>
8+
79
<body>
810
<p><em>Psst: have a look at the JavaScript Console</em> 💁</p>
9-
<script>
10-
// ## Array Cardio Day 2
11-
12-
const people = [
13-
{ name: 'Wes', year: 1988 },
14-
{ name: 'Kait', year: 1986 },
15-
{ name: 'Irv', year: 1970 },
16-
{ name: 'Lux', year: 2015 }
17-
];
18-
19-
const comments = [
20-
{ text: 'Love this!', id: 523423 },
21-
{ text: 'Super good', id: 823423 },
22-
{ text: 'You are the best', id: 2039842 },
23-
{ text: 'Ramen is my fav food ever', id: 123523 },
24-
{ text: 'Nice Nice Nice!', id: 542328 }
25-
];
26-
27-
// Some and Every Checks
28-
// Array.prototype.some() // is at least one person 19 or older?
29-
// Array.prototype.every() // is everyone 19 or older?
30-
31-
// Array.prototype.find()
32-
// Find is like filter, but instead returns just the one you are looking for
33-
// find the comment with the ID of 823423
34-
35-
// Array.prototype.findIndex()
36-
// Find the comment with this ID
37-
// delete the comment with the ID of 823423
38-
39-
</script>
11+
<script src="typescripts.js"></script>
4012
</body>
41-
</html>
13+
14+
</html>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
const comments = [
8+
{ text: 'Love this!', id: 523423 },
9+
{ text: 'Super good', id: 823423 },
10+
{ text: 'You are the best', id: 2039842 },
11+
{ text: 'Ramen is my fav food ever', id: 123523 },
12+
{ text: 'Nice Nice Nice!', id: 542328 }
13+
];
14+
const isAdults = people.some(person => {
15+
const currentYear = (new Date()).getFullYear();
16+
return ((currentYear - person.year) >= 19);
17+
});
18+
console.log({ isAdults });
19+
const allAdult = people.every(person => {
20+
const currentYear = (new Date()).getFullYear();
21+
return ((currentYear - person.year) >= 19);
22+
});
23+
console.log({ allAdult });
24+
const comment = comments.find(comment => comment.id === 823423);
25+
console.log(comment);
26+
console.table(comments);
27+
const index = comments.findIndex(comment => comment.id === 823423);
28+
console.log({ index });
29+
const newComments = [
30+
...comments.slice(0, index),
31+
...comments.slice(index + 1)
32+
];
33+
console.table(newComments);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* JavaScript30 by Wes Bos, https://javascript30.com/
3+
* TypeScript implementation by Will Wager
4+
* Project: Array Cardio 2
5+
* Concepts: Array builtins - some, every, find, findIndex
6+
* Key takeaways: Practice, keep functions pure by spreads with slice instead of splice.
7+
* Sidenotes:
8+
* Log name and value of boolean with an object literal in .log
9+
* Find is not in es5, so I had to use --target es6
10+
*/
11+
12+
// ## Array Cardio Day 2
13+
14+
const people = [
15+
{ name: 'Wes', year: 1988 },
16+
{ name: 'Kait', year: 1986 },
17+
{ name: 'Irv', year: 1970 },
18+
{ name: 'Lux', year: 2015 }
19+
];
20+
21+
const comments = [
22+
{ text: 'Love this!', id: 523423 },
23+
{ text: 'Super good', id: 823423 },
24+
{ text: 'You are the best', id: 2039842 },
25+
{ text: 'Ramen is my fav food ever', id: 123523 },
26+
{ text: 'Nice Nice Nice!', id: 542328 }
27+
];
28+
29+
// Some and Every Checks
30+
// Array.prototype.some() // is at least one person 19 or older?
31+
const isAdults = people.some(person => {
32+
const currentYear = (new Date()).getFullYear();
33+
return ((currentYear - person.year) >= 19);
34+
});
35+
console.log({ isAdults });
36+
37+
// Array.prototype.every() // is everyone 19 or older?
38+
const allAdult = people.every(person => {
39+
const currentYear = (new Date()).getFullYear();
40+
return ((currentYear - person.year) >= 19);
41+
});
42+
console.log({ allAdult });
43+
44+
// Array.prototype.find()
45+
// Find is like filter, but instead returns just the one you are looking for
46+
// find the comment with the ID of 823423
47+
const comment = comments.find(comment => comment.id === 823423);
48+
console.log(comment);
49+
50+
// Array.prototype.findIndex()
51+
// Find the comment with this ID
52+
// delete the comment with the ID of 823423
53+
console.table(comments);
54+
55+
const index = comments.findIndex(comment => comment.id === 823423);
56+
console.log({ index });
57+
58+
const newComments = [
59+
...comments.slice(0, index),
60+
...comments.slice(index + 1)
61+
];
62+
console.table(newComments);

0 commit comments

Comments
 (0)