You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42Lines changed: 42 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
# LAB | JS Functions & Arrays
4
4
5
+
<br>
6
+
5
7
## Introduction
6
8
7
9
Manipulating arrays in code is a very common operation. Whether you are creating a total for a shopping cart, grabbing only the first names out of a list of people, or moving a piece on a chessboard, you are probably going to be modifying or manipulating an array in some way.
@@ -24,8 +26,12 @@ git push origin master
24
26
25
27
Create Pull Request so your TAs can check up your work.
26
28
29
+
<br>
30
+
27
31
## Automated Testing Introduction
28
32
33
+
<br>
34
+
29
35
### What is automated testing?
30
36
31
37
Automated software testing is the process of programmatically executing an application in order to validate and verify that it meets the business needs, as well as the technical requirements, and that it behaves as expected.
@@ -34,10 +40,14 @@ Testing should be viewed as a continuous process, not a discrete operation or si
34
40
35
41
Having strong _test suites_ can provide you ease of mind, since you will be able to confidently improve upon your work while knowing that your not breaking a previously developed feature.
36
42
43
+
<br>
44
+
37
45
### Testing labs
38
46
39
47
This lab, along with some of the labs you will be working on during the bootcamp, has a complete test suite that is meant to ensure that your work fulfills the requirements we established.
40
48
49
+
<br>
50
+
41
51
### Testing with Jest
42
52
43
53
Jest is an automated test-runner for JavaScript.
@@ -48,6 +58,8 @@ We will be working with the `src/functions-and-arrays.js` file. To run your test
48
58
49
59
Open the `lab-solution.html` file using the live server VSCode extension.
50
60
61
+
<br>
62
+
51
63
#### Pass the tests
52
64
53
65
You should work on the `src/functions-and-arrays.js` file. While following the instructions for each iteration, you should check every test and make sure it's _passing_, before moving on.
@@ -58,12 +70,18 @@ When coding with tests, it is super important that you carefully read and unders
58
70
59
71
Note that **you don't need to execute the functions yourself**, the tests are responsible for doing that. All you should do is declare them, make sure they deal with the parameters passed and that they return what is indicated on the iterations and in the test messages. For some iterations we provide you with a sample array, so that you can do some **manual** testing, if you wish.
60
72
73
+
<br>
74
+
61
75
## Instructions
62
76
77
+
<br>
78
+
63
79
### Iteration #1: Find the maximum
64
80
65
81
Define a function `maxOfTwoNumbers` that takes two numbers as arguments and returns the largest.
66
82
83
+
<br>
84
+
67
85
### Iteration #2: Find the longest word
68
86
69
87
Declare a function named `findLongestWord` that takes as an argument an array of words and returns the longest one. If there are 2 with the same length, it should return the first occurrence.
@@ -74,6 +92,8 @@ You can use the following array to test your solution:
#### Bonus - Iteration #4.1: A generic `avg()` function
137
167
138
168
Create function `avg(arr)` that receives any mixed array and calculates average. Consider as mixed array an array filled with numbers and/or strings and/or booleans. We are following a similar logic to the one applied on the bonus iteration 4.1. :wink:
Take the following array, remove the duplicates, and return a new array. You are more than likely going to want to check out the [`indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) Array method.
@@ -167,6 +199,8 @@ const words = [
167
199
];
168
200
```
169
201
202
+
<br>
203
+
170
204
### Iteration #6: Find elements
171
205
172
206
Let's create a simple array search.
@@ -179,6 +213,8 @@ You can use the following array to test your solution:
Declare a function named `howManyTimes` that will take in an array of words as the first argument, and a word to search for as the second argument. The function will return the number of times that word appears in the array.
@@ -201,6 +237,8 @@ const words = [
201
237
];
202
238
```
203
239
240
+
<br>
241
+
204
242
### Bonus - Iteration #8: Product of adjacent numbers
205
243
206
244
What is the greatest product of four adjacent numbers? We consider adjacent any four numbers that are next to each other horizontally or vertically.
@@ -244,8 +282,12 @@ const matrix = [
244
282
];
245
283
```
246
284
285
+
<br>
286
+
247
287
### Bonus - Iteration #8.1: Product of diagonals
248
288
249
289
Following the logic you've used in iteration #8, declare a function called `greatestProductOfDiagonals(matrix)`. It takes a matrix as a parameter and returns the greatest product of any four values layed out diagonally, in either direction.
0 commit comments