-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathactivity-arraysadvanced.html
109 lines (90 loc) · 4.55 KB
/
activity-arraysadvanced.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html>
<head>
<title>AC Workshop - Activity: Find Elements in Arrays</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div class="container">
<div class="container-inner">
<div class="left-sidebar">
<div class="home-anchor">
<h3><a href="index.html">Intro to Programming with JavaScript</a></h3>
</div>
<div class="navigation-links">
<div class="navigation-link-item"><a href="activity-logging.html">Activity: Logging</a></div>
<div class="navigation-link-item"><a href="lecture-variables.html">Lecture: Variables</a></div>
<div class="navigation-link-item"><a href="activity-variables.html">Activity: Variables</a></div>
<div class="navigation-link-item"><a href="lecture-arrays.html">Lecture: Arrays</a></div>
<div class="navigation-link-item"><a href="activity-arrays.html">Activity: Arrays</a></div>
<div class="navigation-link-item"><a href="lecture-conditionals.html">Lecture: Conditionals</a></div>
<div class="navigation-link-item"><a href="activity-conditionals.html">Activity: Conditionals</a></div>
<div class="navigation-link-item"><a href="assignment-webproposal.html">Assignment: Web App Proposal</a></div>
<div class="navigation-link-item"><a href="lecture-loops.html">Lecture: Loops</a></div>
<div class="navigation-link-item"><strong><em><a href="activity-arraysadvanced.html">Activity: Arrays (Advanced)</a></em></strong></div>
<div class="navigation-link-item"><a href="lecture-functions.html">Lecture: Functions</a></div>
<div class="navigation-link-item"><a href="activity-functions.html">Activity: Functions</a></div>
<div class="navigation-link-item"><a href="activity-fizzbuzz.html">Activity: Fizz Buzz</a></div>
<div class="navigation-link-item"><a href="teamchallenge.html">Team Challenge</a></div>
</div>
</div>
<div class="content">
<h1>Activity: Arrays (Advanced)</h1>
<p>
<b>Note</b>: <i>Keep</i> and don't delete these programs you write in this activity, we will re-use them in future lessons! One thing you can do (if you haven't done so already) is create a repl.it account, login, and save your work as you complete the following problems.
</p>
<h2>Find min & max within an array</h2>
<p>
Given an array, write a program that returns the <b>largest</b> element. Then try the <b>smallest</b> element. <i>Hint: this will require variables, loops, and conditionals!</i>
</p>
<pre><code>const arr = [25, 101, 66, 10, 99]
// for the array above, expect:
// largest element => 101
// smallest element => 10
</code></pre>
<h2>Detect if an element is within an array</h2>
<p>
Given an array and a target value, write a program that returns whether or not the target value exists within the array. <i>Hint: what type will the result value be? What should its default value be?</i>
</p>
<pre><code>let result; // what should this be set to by default?
const arr = [25, 101, 66, 10, 99]
let target = 66 // result should be "true"
target = 77 // result should be "false"</code></pre>
<h2>Build a simple array</h2>
<p>
Given an integer size, write a program that builds an array of that size where each element is its own index.
</p>
<pre><code>const integerSize = 10;
// expect array to be: [0,1,2,3,4,5,6,7,8,9]
</code></pre>
<ul>
<li>Try with each element value being double its own index? Or triple?</li>
<li>What about if all the odd indices are double while all the even indices are quadruple?</li>
</ul>
<h2>Range of numbers</h2>
<p>
Given two integers less than 1000, make an array with all the numbers between the two integers (inclusive).
</p>
<pre><code>// Example input:
const lowerBound = 20
const upperBound = 25
// Expected Output: [20,21,22,23,24,25]</code></pre>
<p>
<b>CS/Math Question:</b> How large will the array be with a lowerBound of X and an upperBound of Y?
</p>
<h2>
<h2>Average value</h2>
<p>
Given an array of numbers, find the average (mean) value. You can do this by adding up all the numbers and then dividing by how many you added together.
</p>
<pre><code>// Example input:
const inputArray = [5, 15, 10, 30, 25]
// Expected Output: 17</code></pre>
</div>
</div>
</div>
</body>
</html>