Skip to content

Commit 8ff766d

Browse files
authored
Merge pull request #3925 from ironhack-labs/develop
Review changes in iteration 3.2 and update the test assertion
2 parents 751ea3b + c09a8d0 commit 8ff766d

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Diff for: README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
155155

156156
In iteration 3, you created a function that returns the sum of an array of numbers. But what if we want to calculate the sum of the length of words in an array? What if it also includes _boolean_ values? To achieve this, we must create a function allowing this flexibility.
157157

158-
You should implement the function `sum()` in this iteration. The function should take an array of mixed values - numbers, strings, and booleans. The function should add all the string lengths, numeric values, and numeric values of booleans to the total sum and return the sum. Check the tests for more details.
158+
You should implement the function `sum()` in this iteration. The function should take an array of mixed values - numbers, strings, and booleans. The function should add all the string lengths, numeric values, and numeric values of booleans to the total sum and return the sum.
159159

160160
You can use the following array to test your solution:
161161

@@ -165,6 +165,14 @@ const mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10];
165165
// should return: 57
166166
```
167167

168+
169+
Note: Your function should only accept an array with numbers, strings, or booleans. If the array contains any other data type, such as an object, you should [throw an error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw). In JavaScript, the syntax for throwing an error is as follows:
170+
```javascript
171+
throw new Error("Error message goes here");
172+
```
173+
174+
When specifying the error message, you should be specific and descriptive in explaining the error.
175+
168176
<br>
169177

170178
### Iteration #4: Calculate the average
@@ -581,4 +589,4 @@ If the link shown is the same as the main Ironhack repository, you will need to
581589
582590
[Back to top](#faqs)
583591
584-
</details>
592+
</details>

Diff for: tests/functions-and-arrays.spec.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ describe('Bonus: Calculate the sum', () => {
120120
});
121121

122122
it('should throw an error when unsupported data type (object or array) present in the array', () => {
123-
expect(() => sum([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, [], {}])).toThrow(
124-
new Error("Unsupported data type sir or ma'am")
125-
);
123+
expect(() => sum([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, [], {}])).toThrow();
126124
});
127125

128126
});

0 commit comments

Comments
 (0)