Skip to content

Commit a637cc6

Browse files
committed
fix readme, adjust to new function names
1 parent 39afd0a commit a637cc6

File tree

2 files changed

+48
-108
lines changed

2 files changed

+48
-108
lines changed

README.md

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Introduction
66

7-
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.
7+
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.
88

99
## Requirements
1010

@@ -29,13 +29,13 @@ Create Pull Request so your TAs can check up your work.
2929

3030
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.
3131

32-
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.
32+
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 code bases.
3333

34-
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.
34+
Having a strong _test suite_ 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.
3535

3636
### Testing labs
3737

38-
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.
38+
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.
3939

4040
### Testing with Jasmine
4141

@@ -75,7 +75,7 @@ You should write your code on the `src/functions-and-arrays.js` file. While foll
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

78-
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.
78+
When coding with tests, it is super important that you carefully read and understand the errors you are getting, this way you will know for sure what's expected from your code.
7979

8080
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.
8181

@@ -101,7 +101,7 @@ const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard',
101101

102102
Calculating a sum can be as simple as iterating over an array and adding each of the elements together.
103103

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.
104+
Declare a function named `sumNumbers` 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 will 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.
105105

106106
You can use the following array to test your solution:
107107

@@ -113,9 +113,9 @@ const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
113113

114114
**The goal: Learn how to refactor your code.** :muscle:
115115

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.
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 `sumNumbers()` is called.
117117

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.
118+
Here we are applying a concept we call **polymorphism**, that is, dealing with a functions' input independently of the types they are passed as.
119119

120120
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.
121121

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

134134
**The logic behind this:**
135135

136-
1. Find the sum as we did in the first exercise (or how about reusing that the _sumArray()_?)
136+
1. Find the sum as we did in the first exercise (or how about reusing that the _sumNumbers()_?)
137137
2. Take that sum and divide it by the number of elements in the list.
138138

139139
### Level 1: Array of numbers
140140

141141
Declare a function named `averageNumbers` that expects an array of numbers and returns the average of the numbers:
142142

143-
**Starter Code**
143+
**Starter code**
144144

145145
```javascript
146146
const numbers = [2, 6, 9, 10, 7, 4, 1, 9];
@@ -150,26 +150,15 @@ const numbers = [2, 6, 9, 10, 7, 4, 1, 9];
150150

151151
Declare a function named `averageWordLength` that receives as a single argument an array of words and returns the average length of the words:
152152

153-
**Starter Code**
153+
**Starter code**
154154

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

170159
### Bonus - Iteration #4.1: A generic `avg()` function
171160

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:
161+
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:
173162

174163
```javascript
175164
const mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10];
@@ -179,11 +168,11 @@ const mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10];
179168

180169
## Iteration #5: Unique arrays
181170

182-
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.
171+
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.
183172

184173
Do this in the form of a function `uniquifyArray` that receives an array of words as a argument.
185174

186-
**Starter Code**
175+
**Starter code**
187176

188177
```javascript
189178
const words = [
@@ -207,26 +196,17 @@ Let's create a simple array search.
207196

208197
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.
209198

210-
**Starter Code**
199+
**Starter code**
211200

212201
```javascript
213-
const words = [
214-
'machine',
215-
'subset',
216-
'trouble',
217-
'starting',
218-
'matter',
219-
'eating',
220-
'truth',
221-
'disobedience'
222-
];
202+
const words = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
223203
```
224204

225205
## Iteration #7: Count repetition
226206

227207
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.
228208

229-
**Starter Code**
209+
**Starter code**
230210

231211
```javascript
232212
const words = [

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

Lines changed: 30 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
function shuffle(currentArray) {
2-
const array = currentArray.map(arr => arr.slice());
1+
const shuffle = currentArray => {
2+
const array = [...currentArray];
33
let counter = array.length;
44

55
while (counter > 0) {
6-
let index = Math.floor(Math.random() * counter);
6+
let randomIndex = Math.floor(Math.random() * counter);
77
counter--;
88
let temp = array[counter];
9-
array[counter] = array[index];
10-
array[index] = temp;
9+
array[counter] = array[randomIndex];
10+
array[randomIndex] = temp;
1111
}
1212
return array;
13-
}
13+
};
1414

1515
describe('Find the maximum', () => {
1616
it('should create a function named maxOfTwoNumbers', () => {
@@ -116,8 +116,6 @@ describe('Bonus: Calculate the sum', () => {
116116
expect(sum([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, true])).toBe(47);
117117
});
118118
it('should throw an error when unsupported data type (object or array) present in the array', () => {
119-
// const arr = [6, 12, "miami", 1, "barca", "200", "lisboa", 8, [], {}];
120-
121119
expect(() => sum([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, [], {}])).toThrow(
122120
new Error("Unsupported data type sir or ma'am")
123121
);
@@ -130,19 +128,16 @@ describe('Calculate the average of an array of numbers', () => {
130128
});
131129

132130
it('should return null if receives an empty array when called', () => {
133-
// should it return null or zero?
134131
expect(averageNumbers([])).toBe(null);
135132
});
136133

137-
// do we need this?
138-
// it("should return the average of a one-element array", () => {
139-
// expect(averageNumbers([9])).toBe(9);
140-
// });
134+
it('should return the average of a one-element array', () => {
135+
expect(averageNumbers([9])).toBe(9);
136+
});
141137

142-
// do we need this?
143-
// it("should return the average even with negative values", () => {
144-
// expect(averageNumbers([9, -3, -4, 6])).toBe(2);
145-
// });
138+
it('should return the average even with negative values', () => {
139+
expect(averageNumbers([9, -3, -4, 6])).toBe(2);
140+
});
146141

147142
it('should return the average of the array', () => {
148143
expect(averageNumbers([9, 10, 82, 92, 32, 102, 58])).toBe(55);
@@ -155,27 +150,16 @@ describe('Calculate the average of an array of strings', () => {
155150
});
156151

157152
it('should return null if receives an empty array when called', () => {
158-
// should it return null or zero?
159153
expect(averageWordLength([])).toBe(null);
160154
});
161155

162-
// do we need this?
163-
// it("should return the average of a one-element array", () => {
164-
// expect(averageWordLength(["ironhack"])).toBe(8);
165-
// });
156+
it('should return the average of a one-element array', () => {
157+
expect(averageWordLength(['ironhack'])).toBe(8);
158+
});
166159

167160
it('should return the average of a the array', () => {
168161
expect(
169-
averageWordLength([
170-
'Ironhack',
171-
'Madrid',
172-
'Barcelona',
173-
'Paris',
174-
'Miami',
175-
'Mexico',
176-
'Berlin',
177-
'Programmers'
178-
])
162+
averageWordLength(['Ironhack', 'Madrid', 'Barcelona', 'Paris', 'Miami', 'Mexico', 'Berlin', 'Programmers'])
179163
).toBe(7);
180164
});
181165
});
@@ -186,7 +170,6 @@ describe('Bonus: Calculate the average of a mixed elements array', () => {
186170
});
187171

188172
it('should return null if receives an empty array when called', () => {
189-
// should it return null or zero?
190173
expect(avg([])).toBe(null);
191174
});
192175

@@ -207,31 +190,17 @@ describe('Unique array', () => {
207190
expect(uniquifyArray([])).toEqual(null);
208191
});
209192

210-
// do we need this?
211-
// it("should return the correct uniqified array when an array of the same elements passed as argument", () => {
212-
// expect(uniquifyArray(["Ironhack", "Ironhack", "Ironhack"])).toEqual([
213-
// "Ironhack"
214-
// ]);
215-
// });
193+
it('should return the correct uniqified array when an array of the same elements passed as argument', () => {
194+
expect(uniquifyArray(['Ironhack', 'Ironhack', 'Ironhack'])).toEqual(['Ironhack']);
195+
});
216196

217-
// do we need this?
218-
// it("should return the same array when no element is repeated", () => {
219-
// expect(uniquifyArray(["Cat", "Dog", "Cow"])).toEqual(["Cat", "Dog", "Cow"]);
220-
// });
197+
it('should return the same array when no element is repeated', () => {
198+
expect(uniquifyArray(['Cat', 'Dog', 'Cow'])).toEqual(['Cat', 'Dog', 'Cow']);
199+
});
221200

222201
it('should return the uniquified array', () => {
223202
expect(
224-
uniquifyArray([
225-
'iPhone',
226-
'Samsung',
227-
'Android',
228-
'iOS',
229-
'iPhone',
230-
'Samsung',
231-
'Nokia',
232-
'Blackberry',
233-
'Android'
234-
])
203+
uniquifyArray(['iPhone', 'Samsung', 'Android', 'iOS', 'iPhone', 'Samsung', 'Nokia', 'Blackberry', 'Android'])
235204
).toEqual(['iPhone', 'Samsung', 'Android', 'iOS', 'Nokia', 'Blackberry']);
236205
});
237206
});
@@ -245,25 +214,16 @@ describe('Find elements', () => {
245214
expect(doesWordExist([])).toBe(null);
246215
});
247216

248-
// do we need this test?
249-
// it("should return true if the word we are looking for is the only one in the array", () => {
250-
// expect(doesWordExist(["machine"], "machine")).toBe(true);
251-
// });
217+
it('should return true if the word we are looking for is the only one in the array', () => {
218+
expect(doesWordExist(['machine'], 'machine')).toBe(true);
219+
});
252220

253-
// do we need this test?
254-
// it("should return false if the word we are looking for is not in the array", () => {
255-
// expect(
256-
// doesWordExist(
257-
// ["machine", "poison", "eat", "apple", "horse"],
258-
// "ratatouille"
259-
// )
260-
// ).toBe(false);
261-
// });
221+
it('should return false if the word we are looking for is not in the array', () => {
222+
expect(doesWordExist(['machine', 'poison', 'eat', 'apple', 'horse'], 'ratatouille')).toBe(false);
223+
});
262224

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

0 commit comments

Comments
 (0)