Skip to content

Commit b727b52

Browse files
committed
Merge branch 'josecarneiro-master'
2 parents a672112 + de6499f commit b727b52

File tree

2 files changed

+67
-87
lines changed

2 files changed

+67
-87
lines changed

README.md

Lines changed: 66 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png)
22

3-
# JS | Functions & Arrays
3+
# LAB | JS Functions & Arrays
44

5-
## Learning Goals
6-
7-
In this exercise you will apply:
8-
9-
- Array iteration techniques
10-
- Using functions to manipulate and transform arrays
115

126
## Introduction
137

148
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.
159

16-
1710
## Requirements
1811

1912
- Fork this repo
@@ -22,30 +15,34 @@ Manipulating arrays in code is a very common operation. Whether you're creating
2215
## Submission
2316

2417
Upon completion, run the following commands:
18+
2519
```
2620
$ git add .
2721
$ git commit -m "done"
2822
$ git push origin master
2923
```
24+
3025
Create Pull Request so your TAs can check up your work.
3126

32-
## Testing Introduction
27+
## Automated Testing Introduction
28+
29+
### What is automated testing?
3330

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.
3532

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.
3734

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.
3936

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
4138

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.
4340

4441
### Testing with Jasmine
4542

46-
![Jasmine Logo](https://i.imgur.com/A1pop7h.png)
43+
<!-- ![Jasmine Logo](https://i.imgur.com/A1pop7h.png) -->
4744

48-
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.
4946

5047
We have already included Jasmine in the project you just forked, so let's see how to use it to implement our code.
5148

@@ -65,47 +62,38 @@ starter-code/
6562
└─ SpecRunner.html
6663
```
6764

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.
6966

7067
**Run tests**
7168

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:
7370

7471
![image](https://user-images.githubusercontent.com/23629340/33389609-c2f3965c-d533-11e7-9a03-e0a89314dd98.png)
7572

7673
**Pass the tests**
7774

78-
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_.
7976

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.
8178

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.
8380

8481
## Deliverables
8582

8683
Write your JavaScript in the provided `src/functions-and-arrays.js` file.
8784

88-
8985
## Iteration #1: Find the maximum
9086

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.
9288

9389
## Iteration #2: Finding Longest Word
9490

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.
9692

9793
**Starter Code**
9894

9995
```javascript
100-
const words = [
101-
'mystery',
102-
'brother',
103-
'aviator',
104-
'crocodile',
105-
'pearl',
106-
'orchard',
107-
'crackpot'
108-
];
96+
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
10997
```
11098

11199
## Iteration #3: Calculating a Sum
@@ -114,7 +102,7 @@ Calculating a sum is as simple as iterating over an array and adding each of the
114102

115103
<!-- 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. -->
116104

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.
118106

119107
**Starter Code**
120108

@@ -124,7 +112,7 @@ const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
124112

125113
## Iteration #4: Calculate the Average
126114

127-
Calculating an average is an extremely common task. Let's practice it a bit.
115+
Calculating an average is an extremely common task. Let's practice it a bit.
128116

129117
**Algorithm**
130118

@@ -133,7 +121,7 @@ Calculating an average is an extremely common task. Let's practice it a bit.
133121

134122
### Level 1: Array of Numbers
135123

136-
Write a function `averageNumbers` that receives an array of numbers and calculate the average of the numbers:
124+
Declare a function named `averageNumbers` that expects an array of numbers and returns the average of the numbers:
137125

138126
**Starter Code**
139127

@@ -143,30 +131,30 @@ const numbers = [2, 6, 9, 10, 7, 4, 1, 9];
143131

144132
### Level 2: Array of Strings
145133

146-
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:
147135

148136
**Starter Code**
149137

150138
```javascript
151139
const words = [
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'
162150
];
163151
```
164152

165153
## Iteration #5: Unique Arrays
166154

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.
168156

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.
170158

171159
**Starter Code**
172160

@@ -184,16 +172,16 @@ const words = [
184172
'simple',
185173
'bring'
186174
];
187-
188175
```
189176

190177
## Iteration #6: Finding Elements
191178

192179
Let's create a simple array search.
193180

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.
195182

196183
**Starter Code**
184+
197185
```javascript
198186
const words = [
199187
'machine',
@@ -209,7 +197,7 @@ const words = [
209197

210198
## Iteration #7: Counting Repetition
211199

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.
213201

214202
**Starter Code**
215203

@@ -224,7 +212,7 @@ const words = [
224212
'eating',
225213
'matter',
226214
'truth',
227-
'disobedience'
215+
'disobedience',
228216
'matter'
229217
];
230218
```
@@ -234,40 +222,40 @@ const words = [
234222
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.
235223

236224
For example, if we have a 5x5 Matrix like:
237-
225+
```bash
238226
[ 1, 2, 3, 4, 5]
239227
[ 1, 20, 3, 4, 5]
240228
[ 1, 20, 3, 4, 5]
241229
[ 1, 20, 3, 4, 5]
242230
[ 1, 4, 3, 4, 5]
231+
```
232+
The greatest product will be the `20`x`20`x`20`x`4` = `32000`;
243233

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!
247235

248236
```javascript
249237
const matrix = [
250-
[08,02,22,97,38,15,00,40,00,75,04,05,07,78,52,12,50,77,91,08],
251-
[49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48,04,56,62,00],
252-
[81,49,31,73,55,79,14,29,93,71,40,67,53,88,30,03,49,13,36,65],
253-
[52,70,95,23,04,60,11,42,69,24,68,56,01,32,56,71,37,02,36,91],
254-
[22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80],
255-
[24,47,32,60,99,03,45,02,44,75,33,53,78,36,84,20,35,17,12,50],
256-
[32,98,81,28,64,23,67,10,26,38,40,67,59,54,70,66,18,38,64,70],
257-
[67,26,20,68,02,62,12,20,95,63,94,39,63,08,40,91,66,49,94,21],
258-
[24,55,58,05,66,73,99,26,97,17,78,78,96,83,14,88,34,89,63,72],
259-
[21,36,23,09,75,00,76,44,20,45,35,14,00,61,33,97,34,31,33,95],
260-
[78,17,53,28,22,75,31,67,15,94,03,80,04,62,16,14,09,53,56,92],
261-
[16,39,05,42,96,35,31,47,55,58,88,24,00,17,54,24,36,29,85,57],
262-
[86,56,00,48,35,71,89,07,05,44,44,37,44,60,21,58,51,54,17,58],
263-
[19,80,81,68,05,94,47,69,28,73,92,13,86,52,17,77,04,89,55,40],
264-
[04,52,08,83,97,35,99,16,07,97,57,32,16,26,26,79,33,27,98,66],
265-
[88,36,68,87,57,62,20,72,03,46,33,67,46,55,12,32,63,93,53,69],
266-
[04,42,16,73,38,25,39,11,24,94,72,18,08,46,29,32,40,62,76,36],
267-
[20,69,36,41,72,30,23,88,34,62,99,69,82,67,59,85,74,04,36,16],
268-
[20,73,35,29,78,31,90,01,74,31,49,71,48,86,81,16,23,57,05,54],
269-
[01,70,54,71,83,51,54,69,16,92,33,48,61,43,52,01,89,19,67,48],
238+
[08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08],
239+
[49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00],
240+
[81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65],
241+
[52, 70, 95, 23, 04, 60, 11, 42, 69, 24, 68, 56, 01, 32, 56, 71, 37, 02, 36, 91],
242+
[22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80],
243+
[24, 47, 32, 60, 99, 03, 45, 02, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50],
244+
[32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70],
245+
[67, 26, 20, 68, 02, 62, 12, 20, 95, 63, 94, 39, 63, 08, 40, 91, 66, 49, 94, 21],
246+
[24, 55, 58, 05, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72],
247+
[21, 36, 23, 09, 75, 00, 76, 44, 20, 45, 35, 14, 00, 61, 33, 97, 34, 31, 33, 95],
248+
[78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 03, 80, 04, 62, 16, 14, 09, 53, 56, 92],
249+
[16, 39, 05, 42, 96, 35, 31, 47, 55, 58, 88, 24, 00, 17, 54, 24, 36, 29, 85, 57],
250+
[86, 56, 00, 48, 35, 71, 89, 07, 05, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58],
251+
[19, 80, 81, 68, 05, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 04, 89, 55, 40],
252+
[04, 52, 08, 83, 97, 35, 99, 16, 07, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66],
253+
[88, 36, 68, 87, 57, 62, 20, 72, 03, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69],
254+
[04, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 08, 46, 29, 32, 40, 62, 76, 36],
255+
[20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 04, 36, 16],
256+
[20, 73, 35, 29, 78, 31, 90, 01, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 05, 54],
257+
[01, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 01, 89, 19, 67, 48]
270258
];
271259
```
272260

273-
**Happy coding!** :heart:
261+
**Happy coding!** :heart:

starter-code/src/functions-and-arrays.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
// Find the maximum
22

33
// Finding Longest Word
4-
const words = [
5-
'mystery',
6-
'brother',
7-
'aviator',
8-
'crocodile',
9-
'pearl',
10-
'orchard',
11-
'crackpot'
12-
];
4+
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
135

146
// Calculating a Sum
157

0 commit comments

Comments
 (0)