Skip to content

Commit 9278e24

Browse files
committed
Merge branch 'master' into tests-update, made small refactors in instructions and tests
2 parents c18234f + eb98808 commit 9278e24

File tree

3 files changed

+99
-22
lines changed

3 files changed

+99
-22
lines changed

.github/stale.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Configuration for probot-stale - https://github.com/probot/stale
2+
3+
# Number of days of inactivity before an Issue or Pull Request becomes stale
4+
daysUntilStale: 30
5+
6+
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
7+
exemptLabels: []
8+
9+
# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
10+
# onlyLabels:
11+
# - TestLabel
12+
13+
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
14+
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
15+
daysUntilClose: 2
16+
17+
# Label to use when marking as stale
18+
staleLabel: stale
19+
20+
# Comment to post when marking as stale. Set to `false` to disable
21+
markComment: >
22+
This pull request has been automatically marked as stale because it didn't have any recent activity. It will be closed if no further activity occurs. Thank you
23+
for your contributions.
24+
closeComment: >
25+
This pull request is closed. Thank you.

README.md

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,28 @@ starter-code/
5757
├── src
5858
│   └── functions-and-arrays.js
5959
├── tests
60-
│   └── FunctionsAndArraysSpec.js
60+
│   └── functions-and-arrays.spec.js
6161
└─ SpecRunner.html
6262
```
6363

6464
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.
6565

66-
**Run tests**
66+
#### Run tests
6767

6868
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:
6969

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

72-
**Pass the tests**
72+
#### Pass the tests
7373

74-
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_.
74+
You should write your code 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.
7575

7676
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.
7777

7878
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.
7979

80+
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.
81+
8082
## Deliverables
8183

8284
Write your JavaScript in the provided `src/functions-and-arrays.js` file.
@@ -97,9 +99,9 @@ const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard',
9799

98100
## Iteration #3: Calculate the sum
99101

100-
Calculating a sum is as simple as iterating over an array and adding each of the elements together.
102+
Calculating a sum can be as simple as iterating over an array and adding each of the elements together.
101103

102-
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. For now, let's practice _"manual"_ way using loops.
104+
Declare a function named `sumArray` that takes an array of numbers as an argument, 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. For now, let's practice _"declarative"_ way adding values, using loops.
103105

104106
You can use the following array to test your solution:
105107

@@ -110,16 +112,19 @@ const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
110112
### Bonus - Iteration #3.1: A generic `sum()` function
111113

112114
**The goal: Learn how to refactor your code.** :muscle:
113-
In the iteration 3, you created a function that will return a sum of array of numbers. But what if we want to know how much is a sum of some array of words? We wouldn't be able to use the same function as above, or better saying, we would have to _tweak_ it a little bit so it can be reused no matter what is in the array that is passed as argument when function _sumArray()_ is called.
114115

115-
Let's create a new function `sum()` that calculates the sum for array filled with (_almost_) any type of data. Check the tests for more details.
116+
In the iteration 3, you created a function that returns the sum of an array of numbers. But what if we wanted to know how much is the sum of the length of all of the words in an array? What if we wanted to add _boolean_ values to the mix? We wouldn't be able to use the same function as above, or better saying, we would have to _tweak_ it a little bit so that it can be reused no matter what is in the array that is passed as argument when function `sumArray()` is called.
117+
118+
Here we're applying a concept we call **polymorphism**, that is, dealing with a functions' input independently of the types they're passed as.
119+
120+
Let's create a new function `sum()` that calculates the sum for array filled with (_almost_) any type of data. Note that strings should have their length added to the total, and boolean values should be coerced into their corresponding numeric values. Check the tests for more details.
116121

117122
You can use the following array to test your solution:
118123

119124
```javascript
120-
const mixedArr = [6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, 10];
125+
const mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10];
121126

122-
// should return: 56
127+
// should return: 57
123128
```
124129

125130
## Iteration #4: Calculate the average
@@ -148,17 +153,28 @@ Declare a function named `averageWordLength` that receives as a single argument
148153
**Starter Code**
149154

150155
```javascript
151-
const words = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];
156+
const words = [
157+
'seat',
158+
'correspond',
159+
'linen',
160+
'motif',
161+
'hole',
162+
'smell',
163+
'smart',
164+
'chaos',
165+
'fuel',
166+
'palace'
167+
];
152168
```
153169

154170
### Bonus - Iteration #4.1: A generic `avg()` function
155171

156-
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.
172+
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're following a similar logic to the one applied on the bonus iteration 4.1 :wink:
157173

158174
```javascript
159-
const mixedArr = [6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, 10];
175+
const mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10];
160176

161-
// should return: 6.22
177+
// should return: 5.7
162178
```
163179

164180
## Iteration #5: Unique arrays
@@ -194,7 +210,16 @@ Declare a function named `doesWordExist` that will take in an array of words as
194210
**Starter Code**
195211

196212
```javascript
197-
const words = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
213+
const words = [
214+
'machine',
215+
'subset',
216+
'trouble',
217+
'starting',
218+
'matter',
219+
'eating',
220+
'truth',
221+
'disobedience'
222+
];
198223
```
199224

200225
## Iteration #7: Count repetition
@@ -219,9 +244,9 @@ const words = [
219244
];
220245
```
221246

222-
## Iteration #8: Bonus
247+
## Bonus - Iteration #8: Product of adjacent numbers
223248

224-
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.
249+
What is the greatest product of four adjacent numbers? We consider adjacent any four numbers that are next to each other horizontally or vertically.
225250

226251
For example, if we have a 5x5 Matrix like:
227252

@@ -235,7 +260,7 @@ For example, if we have a 5x5 Matrix like:
235260

236261
The greatest product will be the `20`x`20`x`20`x`4` = `32000`;
237262

238-
Declare a function named `greatestProduct` to find it in the 20×20 grid below!
263+
Declare a function named `greatestProduct(matrix)` to find it in the 20×20 grid below!
239264

240265
```javascript
241266
const matrix = [
@@ -262,4 +287,8 @@ const matrix = [
262287
];
263288
```
264289

290+
## Bonus - Iteration #8.1: Product of diagonals
291+
292+
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.
293+
265294
**Happy coding!** :heart:

starter-code/tests/functions-and-arrays.spec.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ describe('Find the maximum', () => {
1919

2020
it('should return greater of two arguments - if the first argument greater', () => {
2121
expect(maxOfTwoNumbers(2, 1)).toBe(2);
22+
expect(maxOfTwoNumbers(5, -7)).toBe(5);
2223
});
2324

2425
it('should return greater of two arguments - if the second argument greater', () => {
2526
expect(maxOfTwoNumbers(1, 3)).toBe(3);
27+
expect(maxOfTwoNumbers(-5, 3)).toBe(3);
2628
});
2729

28-
it('should return greater of two arguments - if two arguments are equal', () => {
30+
it('should return either arguments - if both arguments are equal', () => {
2931
expect(maxOfTwoNumbers(4, 4)).toBe(4);
3032
});
3133
});
@@ -164,7 +166,16 @@ describe('Calculate the average of an array of strings', () => {
164166

165167
it('should return the average of a the array', () => {
166168
expect(
167-
averageWordLength(['Ironhack', 'Madrid', 'Barcelona', 'Paris', 'Miami', 'Mexico', 'Berlin', 'Programmers'])
169+
averageWordLength([
170+
'Ironhack',
171+
'Madrid',
172+
'Barcelona',
173+
'Paris',
174+
'Miami',
175+
'Mexico',
176+
'Berlin',
177+
'Programmers'
178+
])
168179
).toBe(7);
169180
});
170181
});
@@ -210,7 +221,17 @@ describe('Unique array', () => {
210221

211222
it('should return the uniquified array', () => {
212223
expect(
213-
uniquifyArray(['iPhone', 'Samsung', 'Android', 'iOS', 'iPhone', 'Samsung', 'Nokia', 'Blackberry', 'Android'])
224+
uniquifyArray([
225+
'iPhone',
226+
'Samsung',
227+
'Android',
228+
'iOS',
229+
'iPhone',
230+
'Samsung',
231+
'Nokia',
232+
'Blackberry',
233+
'Android'
234+
])
214235
).toEqual(['iPhone', 'Samsung', 'Android', 'iOS', 'Nokia', 'Blackberry']);
215236
});
216237
});
@@ -240,7 +261,9 @@ describe('Find elements', () => {
240261
// });
241262

242263
it('should return true if the word we are looking for is in the array', () => {
243-
expect(doesWordExist(['pizza', 'sandwich', 'snack', 'soda', 'book', 'computer'], 'book')).toBe(true);
264+
expect(doesWordExist(['pizza', 'sandwich', 'snack', 'soda', 'book', 'computer'], 'book')).toBe(
265+
true
266+
);
244267
});
245268
});
246269

0 commit comments

Comments
 (0)