Skip to content

Commit 82073f5

Browse files
committed
updated
1 parent f0e33ef commit 82073f5

File tree

2 files changed

+141
-50
lines changed

2 files changed

+141
-50
lines changed
Lines changed: 88 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,94 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8">
5-
<title>Array Cardio 💪💪</title>
6-
</head>
7-
<body>
8-
<p><em>Psst: have a look at the JavaScript Console</em> 💁</p>
9-
<script>
10-
// ## Array Cardio Day 2
113

12-
const people = [
13-
{ name: 'Wes', year: 1988 },
14-
{ name: 'Kait', year: 1986 },
15-
{ name: 'Irv', year: 1970 },
16-
{ name: 'Lux', year: 2015 }
17-
];
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>Array Cardio 💪💪</title>
7+
</head>
188

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-
];
9+
<body>
10+
<p><em>Psst: have a look at the JavaScript Console</em> 💁</p>
11+
<script>
12+
// ## Array Cardio Day 2
13+
const people = [{
14+
name: 'Wes',
15+
year: 1988
16+
}, {
17+
name: 'Kait',
18+
year: 1986
19+
}, {
20+
name: 'Irv',
21+
year: 1970
22+
}, {
23+
name: 'Lux',
24+
year: 2015
25+
}];
26+
const comments = [{
27+
text: 'Love this!',
28+
id: 523423
29+
}, {
30+
text: 'Super good',
31+
id: 823423
32+
}, {
33+
text: 'You are the best',
34+
id: 2039842
35+
}, {
36+
text: 'Ramen is my fav food ever',
37+
id: 123523
38+
}, {
39+
text: 'Nice Nice Nice!',
40+
id: 542328
41+
}];
42+
// Some and Every Checks
43+
// Array.prototype.some() // is at least one person 19 or older?
44+
// Array.prototype.every() // is everyone 19 or older?
45+
// const isAdult = people.some(function(person) {
46+
// const currentYear = (new Date()).getFullYear();
47+
// if ((currentYear - person.year) >= 19) {
48+
// return true;
49+
// }
50+
// });
51+
const isAdult = people.some(person => ((new Date()).getFullYear() - person.year) >= 19);
52+
console.log(isAdult);
53+
const allAdults = people.every(person => ((new Date()).getFullYear() - person.year) >= 19);
54+
console.log(allAdults);
55+
// Array.prototype.find()
56+
// Find is like filter, but instead returns just the one you are looking for
57+
// find the comment with the ID of 823423
58+
const thisComment = comments.find(comment => (comment.id === 823423));
59+
console.log(thisComment);
60+
// Array.prototype.findIndex()
61+
// Find the comment with this ID
62+
// delete the comment with the ID of 823423
63+
const index = comments.findIndex(comment => comment.id === 823423);
64+
console.table(comments);
65+
//const newComments = comments.slice(index, 1);
66+
console.table(comments.splice(index, 1));
67+
// problems
68+
// 1.4 Given an array of integers, find the largest difference between two elements such that the element of lesser value must come before the greater element
69+
var array = [7, 8, 4, 9, 9, 15, 3, 1, 10];
2670

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?
71+
function sortArray(a, b) {
72+
return a - b;
73+
}
74+
var maybe = array.filter(function(val, i, ary) {
75+
if (i > 0) {
76+
if ((val > ary[i - 1])) {
77+
// console.log('val: ' + val);
78+
// console.log('previous val: ' + ary[i - 1]);
79+
// console.log((val - ary[i - 1]));
80+
return parseInt(val) - parseInt((ary[i - 1]));
81+
//return val
82+
}
83+
//console.log(val);
84+
//console.log(val - ary[i - 1]);
85+
//return diff(val, ary[i - 1]);
86+
}
87+
});
88+
//var largest = (maybe.sort(sortArray).reverse())[0];
89+
console.log(maybe);
90+
//console.log(maybe.sort(sortArray).reverse());
91+
</script>
92+
</body>
3093

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>
40-
</body>
41-
</html>
94+
</html>
Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,57 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8">
5-
<title>HTML5 Canvas</title>
6-
</head>
7-
<body>
8-
<canvas id="draw" width="800" height="800"></canvas>
9-
<script>
10-
</script>
113

12-
<style>
13-
html, body {
14-
margin:0;
15-
}
16-
</style>
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>HTML5 Canvas</title>
7+
</head>
178

18-
</body>
19-
</html>
9+
<body> <canvas id="draw" width="800" height="800"></canvas>
10+
<script>
11+
const canvas = document.querySelector('#draw');
12+
const ctx = canvas.getContext('2d');
13+
canvas.width = window.innerWidth;
14+
canvas.height = window.innerHeight;
15+
ctx.strokeStyle = '#BADASS';
16+
ctx.lineJoin = 'round';
17+
ctx.lineCap = 'round';
18+
ctx.lineWidth = 100;
19+
let isDrawing = false;
20+
let lastX = 0;
21+
let lastY = 0;
22+
let hue = 0;
23+
let direction = true;
24+
25+
function draw(e) {
26+
if (!isDrawing) return;
27+
console.log(e);
28+
ctx.strokeStyle = `hsl(${hue}, 100%, 50%)`;
29+
ctx.beginPath();
30+
ctx.moveTo(lastX, lastY);
31+
ctx.lineTo(e.offsetX, e.offsetY);
32+
ctx.stroke();
33+
[lastX, lastY] = [e.offsetX, e.offsetY];
34+
hue++;
35+
if (hue >= 360) hue = 0;
36+
if (ctx.lineWidth >= 100 || ctx.lineWidth <= 1) {
37+
direction = !direction;
38+
}
39+
direction ? ctx.lineWidth++ : ctx.lineWidth--;
40+
}
41+
canvas.addEventListener('mousedown', (e) => {
42+
isDrawing = true;
43+
[lastX, lastY] = [e.offsetX, e.offsetY];
44+
});
45+
canvas.addEventListener('mousemove', draw);
46+
canvas.addEventListener('mouseup', () => isDrawing = false);
47+
canvas.addEventListener('mouseout', () => isDrawing = false);
48+
</script>
49+
<style>
50+
html,
51+
body {
52+
margin: 0;
53+
}
54+
</style>
55+
</body>
56+
57+
</html>

0 commit comments

Comments
 (0)