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
- Using functions to manipulate and transform arrays
11
5
12
6
## Introduction
13
7
14
8
Manipulating arrays in code is a very common operation. Whether you're 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're probably going to be modifying or manipulating an array in some way.
15
9
16
-
17
10
## Requirements
18
11
19
12
- Fork this repo
@@ -22,30 +15,34 @@ Manipulating arrays in code is a very common operation. Whether you're creating
22
15
## Submission
23
16
24
17
Upon completion, run the following commands:
18
+
25
19
```
26
20
$ git add .
27
21
$ git commit -m "done"
28
22
$ git push origin master
29
23
```
24
+
30
25
Create Pull Request so your TAs can check up your work.
31
26
32
-
## Testing Introduction
27
+
## Automated Testing Introduction
28
+
29
+
### What is automated testing?
33
30
34
-
### What is testing?
31
+
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.
35
32
36
-
Software testing is a process of executing an application to validate and verify that it meets the business and technical requirements and works as expected.
33
+
Testing should be viewed as a continuous process, not a discrete operation or single activity in the development lifecycle. Designing tests at the beginning of the product lifecycle can be help to mitigate common issues that arise when developing complex codebases.
37
34
38
-
Testing is a process, not a single activity. So the process of designing tests early at the beginning of the development and the product's lifecycle can help to prevent deficiencies in the code or product design.
35
+
Having a strong _test suite_ can provide you ease of mind, since you'll be able to confidently improve upon your work while knowing that your not breaking a previously developed feature.
39
36
40
-
We have created all the tests you need to create the solution, and you have to execute them all and create the code to accomplish all the requirements.
37
+
### Testing labs
41
38
42
-
Tests prove that your code actually works in every situation in which it’s designed to work. Even when you are improving the design or creating new features, you can change your current code without breaking what already works.
39
+
This lab, along with some of the labs you'll be working on during the bootcamp, has a complete test suite that is meant to ensure that your work fulfills the requirements we established.
Jasmine is an automated testing framework for JavaScript. It is designed to be used in BDD (behavior-driven development) programming which focuses more on the business value than on the technical details.
45
+
Jasmine is an automated testing framework for JavaScript. It is designed to be used in Behavior-driven Development (**BDD**) programming, which focuses more on the business value than on the technical details.
49
46
50
47
We have already included Jasmine in the project you just forked, so let's see how to use it to implement our code.
51
48
@@ -65,47 +62,38 @@ starter-code/
65
62
└─ SpecRunner.html
66
63
```
67
64
68
-
We will be working with the `functions-and-arrays.js` file inside the `src` folder. In the `jasmine` folder you can find all the files that compose Jasmine, that is already linked with the `SpecRunner.html` file.
65
+
We will be working with the `functions-and-arrays.js` file inside of the `src` folder. In the `jasmine` folder you can find all of the files that compose Jasmine, that is already linked with the `SpecRunner.html` file.
69
66
70
67
**Run tests**
71
68
72
-
Run the tests with Jasmine is super easy, you just have to open the `SpecRunner.html` file in your browser. You will find something like this:
69
+
Running automated tests with Jasmine is super easy. All you need to do is open the `SpecRunner.html` file in your browser. You will find something similar this:
You have to write your code on the `src/functions-and-arrays.js` file. Following the instructions, you should go step by step passing all the tests.
75
+
You should write your code on the `src/functions-and-arrays.js` file. By following the instructions for each iteration, you should go every test and make sure it's _passing_.
79
76
80
-
Do not rush to go through all of them at once, take your time to read carefully about what the iteration is asking you, and solve the errors one by one.
77
+
Do not rush. You should take your time to carefully read every iteration, and you should address the _breaking_ tests as you progress through the exercise.
81
78
82
-
When coding with tests, is super important to read and understand the errors we are having for each test, this way we will know what it expect from your code.
79
+
When coding with tests, it is super important that you carefully read and understand the errors you're getting, this way you'll know for sure what's expected from your code.
83
80
84
81
## Deliverables
85
82
86
83
Write your JavaScript in the provided `src/functions-and-arrays.js` file.
87
84
88
-
89
85
## Iteration #1: Find the maximum
90
86
91
-
Define a function `maxOfTwoNumbers` that takes two numbers as arguments and returns the largest.
87
+
Define a function `maxOfTwoNumbers` that takes two numbers as arguments and returns the largest.
92
88
93
89
## Iteration #2: Finding Longest Word
94
90
95
-
Write a function `findLongestWord` that takes an array of words and returns the longest one. If there are 2 with the same length, it should return the first occurrence.
91
+
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.
@@ -114,7 +102,7 @@ Calculating a sum is as simple as iterating over an array and adding each of the
114
102
115
103
<!-- Semantically [reduce](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce) is the best method to use for this, but you can use any loop we've discussed so far. -->
116
104
117
-
Create a `sumArray`function that takes an array of numbers as a parameter, and calculate the sum of all its numbers. Later in the course you will learn how to use some array methods and you won't have to do this process "manually".
105
+
Declare a function named `sumArray` that takes as an argument an array of numbers, and returns the sum of all of the numbers in the array. Later in the course we'll learn how to do this by using the `reduce` array method, which will make your work significantly easier.
Write a function `averageWordLength` that receives an array of words and calculate the average length of the words:
134
+
Declare a function named `averageWordLength` that receives as a single argument an array of words and returns the average length of the words:
147
135
148
136
**Starter Code**
149
137
150
138
```javascript
151
139
constwords= [
152
-
'seat',
153
-
'correspond',
154
-
'linen',
155
-
'motif',
156
-
'hole',
157
-
'smell',
158
-
'smart',
159
-
'chaos',
160
-
'fuel',
161
-
'palace'
140
+
'seat',
141
+
'correspond',
142
+
'linen',
143
+
'motif',
144
+
'hole',
145
+
'smell',
146
+
'smart',
147
+
'chaos',
148
+
'fuel',
149
+
'palace'
162
150
];
163
151
```
164
152
165
153
## Iteration #5: Unique Arrays
166
154
167
-
Take the following array, remove the duplicates, and return a new array. You're 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)function.
155
+
Take the following array, remove the duplicates, and return a new array. You're 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.
168
156
169
-
Do this in the form of a function `uniquifyArray` that receives an array of words as a parameter.
157
+
Do this in the form of a function `uniquifyArray` that receives an array of words as a argument.
170
158
171
159
**Starter Code**
172
160
@@ -184,16 +172,16 @@ const words = [
184
172
'simple',
185
173
'bring'
186
174
];
187
-
188
175
```
189
176
190
177
## Iteration #6: Finding Elements
191
178
192
179
Let's create a simple array search.
193
180
194
-
Write a function `doesWordExist` that will take in an array of words as one argument, and a word to search for as the other. Return `true` if it exists, otherwise, return `false`. **Don't** use `indexOf` for this one. :)
181
+
Declare a function named `doesWordExist` that will take in an array of words as one argument, and a word to search for as the other. Return `true` if it exists, otherwise, return `false`. **Don't** use `indexOf` for this one.
195
182
196
183
**Starter Code**
184
+
197
185
```javascript
198
186
constwords= [
199
187
'machine',
@@ -209,7 +197,7 @@ const words = [
209
197
210
198
## Iteration #7: Counting Repetition
211
199
212
-
Write a function `howManyTimes` that will take in an array of words as one argument, and a word to search for as the other. The function will return the number of times that word appears in the array.
200
+
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.
213
201
214
202
**Starter Code**
215
203
@@ -224,7 +212,7 @@ const words = [
224
212
'eating',
225
213
'matter',
226
214
'truth',
227
-
'disobedience'
215
+
'disobedience',
228
216
'matter'
229
217
];
230
218
```
@@ -234,40 +222,40 @@ const words = [
234
222
What is the greatest product of four adjacent numbers? We consider adjacent any four numbers that are next to each other in horizontal, vertical o diagonal.
235
223
236
224
For example, if we have a 5x5 Matrix like:
237
-
225
+
```bash
238
226
[ 1, 2, 3, 4, 5]
239
227
[ 1, 20, 3, 4, 5]
240
228
[ 1, 20, 3, 4, 5]
241
229
[ 1, 20, 3, 4, 5]
242
230
[ 1, 4, 3, 4, 5]
231
+
```
232
+
The greatest product will be the `20`x`20`x`20`x`4` = `32000`;
243
233
244
-
The greatest product will be the 20x20x20x4 = 32,000;
245
-
246
-
Write a function greatestProduct to find it in the 20×20 grid below!
234
+
Declare a function named `greatestProduct` to find it in the 20×20 grid below!
0 commit comments