Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8af93b4

Browse files
refresh the tests
1 parent 306a8ff commit 8af93b4

File tree

1 file changed

+58
-59
lines changed

1 file changed

+58
-59
lines changed

‎starter-code/tests/FunctionsAndArraysSpec.js

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,119 @@
11
function shuffle(currentArray) {
2-
var array = currentArray.map(function(arr) {
3-
return arr.slice();
4-
});
5-
var counter = array.length;
2+
const array = currentArray.map(arr => arr.slice());
3+
const counter = array.length;
4+
65
while (counter > 0) {
7-
var index = Math.floor(Math.random() * counter);
6+
let index = Math.floor(Math.random() * counter);
87
counter--;
9-
var temp = array[counter];
8+
let temp = array[counter];
109
array[counter] = array[index];
1110
array[index] = temp;
1211
}
1312
return array;
1413
}
15-
describe("Find the maximum - maxOfTwoNumbers", function() {
16-
it("Defines maxOfTwoNumbers", function() {
14+
describe("Find the maximum - maxOfTwoNumbers", ()=> {
15+
it("Defines maxOfTwoNumbers", ()=> {
1716
expect(typeof maxOfTwoNumbers).toBe("function");
1817
});
1918

20-
it("First parameter larger", function() {
19+
it("First parameter larger", ()=> {
2120
expect(maxOfTwoNumbers(2, 1)).toBe(2);
2221
});
2322

24-
it("Second parameter larger", function() {
23+
it("Second parameter larger", ()=> {
2524
expect(maxOfTwoNumbers(1, 3)).toBe(3);
2625
});
2726

28-
it("First and Second parameter equal", function() {
27+
it("First and Second parameter equal", ()=> {
2928
expect(maxOfTwoNumbers(4, 4)).toBe(4);
3029
});
3130
});
3231

33-
describe("Finding Longest Word - findLongestWord", function() {
32+
describe("Finding Longest Word - findLongestWord", ()=> {
3433
it("Defines findLongestWord", function() {
3534
expect(typeof findLongestWord).toBe("function");
3635
});
3736

38-
it("returns null when called with an empty array", function() {
37+
it("returns null when called with an empty array", ()=> {
3938
expect(findLongestWord([])).toBe(null);
4039
});
4140

42-
it("returns the word when called with a single-word array", function() {
41+
it("returns the word when called with a single-word array", ()=> {
4342
expect(findLongestWord(["foo"])).toBe("foo");
4443
});
4544

46-
it("returns the first occurrence word when longest have multiple occurrences ", function() {
45+
it("returns the first occurrence word when longest have multiple occurrences ", ()=> {
4746
expect(findLongestWord(["foo", "bar"])).toBe("foo");
4847
expect(findLongestWord(["bar", "foo"])).toBe("bar");
4948
});
5049

51-
it("returns the longest occurrence when it has multiple words", function() {
52-
var words = ["a", "zab", "12abc", "$$abcd", "abcde", "ironhack"];
53-
for (var i = 0; i < 10; i++) {
50+
it("returns the longest occurrence when it has multiple words", ()=> {
51+
const words = ["a", "zab", "12abc", "$$abcd", "abcde", "ironhack"];
52+
for (let i = 0; i < 10; i++) {
5453
words = shuffle(words);
5554
expect(findLongestWord(words)).toBe("ironhack");
5655
}
5756
});
5857
});
5958

60-
describe("Calculating a Sum - sumArray", function() {
61-
it("Defines sumArray", function() {
59+
describe("Calculating a Sum - sumArray", ()=> {
60+
it("Defines sumArray", ()=> {
6261
expect(typeof sumArray).toBe("function");
6362
});
6463

65-
it("returns zero with an empty array", function() {
64+
it("returns zero with an empty array", ()=> {
6665
expect(sumArray([])).toBe(0);
6766
});
6867

69-
it("returns the sum with one number array", function() {
68+
it("returns the sum with one number array", ()=> {
7069
expect(sumArray([4])).toBe(4);
7170
});
7271

73-
it("returns zero if all elements are zero", function() {
72+
it("returns zero if all elements are zero", ()=> {
7473
expect(sumArray([0, 0, 0, 0, 0])).toBe(0);
7574
});
7675

77-
it("returns the sum", function() {
76+
it("returns the sum", ()=> {
7877
expect(sumArray([10, 5, 4, 32, 8])).toBe(59);
7978
});
8079
});
8180

82-
describe("Calculating the Average - averageNumbers", function() {
83-
it("Defines averageNumbers", function() {
81+
describe("Calculating the Average - averageNumbers", ()=> {
82+
it("Defines averageNumbers", ()=> {
8483
expect(typeof averageNumbers).toBe("function");
8584
});
8685

87-
it("returns null with an empty array", function() {
86+
it("returns null with an empty array", ()=> {
8887
expect(averageNumbers([])).toBe(null);
8988
});
9089

91-
it("returns the average of a unique element array", function() {
90+
it("returns the average of a unique element array", ()=> {
9291
expect(averageNumbers([9])).toBe(9);
9392
});
9493

95-
it("returns the average even with negative values", function() {
94+
it("returns the average even with negative values", ()=> {
9695
expect(averageNumbers([9, -3, -4, 6])).toBe(2);
9796
});
9897

99-
it("returns the average of the array", function() {
98+
it("returns the average of the array", ()=> {
10099
expect(averageNumbers([9, 10, 82, 92, 32, 102, 58])).toBe(55);
101100
});
102101
});
103102

104-
describe("Calculating the Average - averageWordLength", function() {
105-
it("Defines averageWordLength", function() {
103+
describe("Calculating the Average - averageWordLength", ()=> {
104+
it("Defines averageWordLength", ()=> {
106105
expect(typeof averageWordLength).toBe("function");
107106
});
108107

109-
it("returns null with an empty array", function() {
108+
it("returns null with an empty array", ()=> {
110109
expect(averageWordLength([])).toBe(null);
111110
});
112111

113-
it("returns the average of a unique element array", function() {
112+
it("returns the average of a unique element array", ()=> {
114113
expect(averageWordLength(["ironhack"])).toBe(8);
115114
});
116115

117-
it("returns the average of a the array", function() {
116+
it("returns the average of a the array", ()=> {
118117
expect(
119118
averageWordLength([
120119
"Ironhack",
@@ -130,26 +129,26 @@ describe("Calculating the Average - averageWordLength", function() {
130129
});
131130
});
132131

133-
describe("Unique Arrays - uniquifyArray", function() {
134-
it("Defines uniquifyArray", function() {
132+
describe("Unique Arrays - uniquifyArray", ()=> {
133+
it("Defines uniquifyArray", ()=> {
135134
expect(typeof uniquifyArray).toBe("function");
136135
});
137136

138-
it("returns [] with an empty array", function() {
137+
it("returns [] with an empty array", ()=> {
139138
expect(uniquifyArray([])).toEqual([]);
140139
});
141140

142-
it("returns the correct array when having an array of the same element", function() {
141+
it("returns the correct array when having an array of the same element", ()=> {
143142
expect(uniquifyArray(["Ironhack", "Ironhack", "Ironhack"])).toEqual([
144143
"Ironhack"
145144
]);
146145
});
147146

148-
it("returns the same array when no element is repeated", function() {
147+
it("returns the same array when no element is repeated", ()=> {
149148
expect(uniquifyArray(["Cat", "Dog", "Cow"])).toEqual(["Cat", "Dog", "Cow"]);
150149
});
151150

152-
it("returns the uniquified array", function() {
151+
it("returns the uniquified array", ()=> {
153152
expect(
154153
uniquifyArray([
155154
"iPhone",
@@ -166,20 +165,20 @@ describe("Unique Arrays - uniquifyArray", function() {
166165
});
167166
});
168167

169-
describe("Finding Elements - doesWordExist", function() {
170-
it("Defines doesWordExist", function() {
168+
describe("Finding Elements - doesWordExist", ()=> {
169+
it("Defines doesWordExist", ()=> {
171170
expect(typeof doesWordExist).toBe("function");
172171
});
173172

174-
it("returns false with an empty array", function() {
173+
it("returns false with an empty array", ()=> {
175174
expect(doesWordExist([])).toBe(false);
176175
});
177176

178-
it("returns true if the word we are looking is the only one on the array", function() {
177+
it("returns true if the word we are looking is the only one on the array", ()=> {
179178
expect(doesWordExist(["machine"], "machine")).toBe(true);
180179
});
181180

182-
it("returns false if the word we are looking is not in the array", function() {
181+
it("returns false if the word we are looking is not in the array", ()=> {
183182
expect(
184183
doesWordExist(
185184
["machine", "poison", "eat", "apple", "horse"],
@@ -188,7 +187,7 @@ describe("Finding Elements - doesWordExist", function() {
188187
).toBe(false);
189188
});
190189

191-
it("returns true if the word we are looking is in the array", function() {
190+
it("returns true if the word we are looking is in the array", ()=> {
192191
expect(
193192
doesWordExist(
194193
["pizza", "sandwich", "snack", "soda", "book", "computer"],
@@ -198,26 +197,26 @@ describe("Finding Elements - doesWordExist", function() {
198197
});
199198
});
200199

201-
describe("Counting Repetition - howManyTimes", function() {
202-
it("Defines howManyTimes", function() {
200+
describe("Counting Repetition - howManyTimes", ()=> {
201+
it("Defines howManyTimes", ()=> {
203202
expect(typeof howManyTimes).toBe("function");
204203
});
205204

206-
it("returns 0 with an empty array", function() {
205+
it("returns 0 with an empty array", ()=> {
207206
expect(howManyTimes([])).toBe(0);
208207
});
209208

210-
it("returns one when the word appears only one time on the array", function() {
209+
it("returns one when the word appears only one time on the array", ()=> {
211210
expect(howManyTimes(["basketball", "football", "tennis"], "tennis")).toBe(
212211
1
213212
);
214213
});
215214

216-
it("returns zero when the word does not appears on the array", function() {
215+
it("returns zero when the word does not appears on the array", ()=> {
217216
expect(howManyTimes(["basketball", "football", "tennis"], "rugby")).toBe(0);
218217
});
219218

220-
it("returns five when the word appears 5 times on the array", function() {
219+
it("returns five when the word appears 5 times on the array", ()=> {
221220
expect(
222221
howManyTimes(
223222
[
@@ -239,13 +238,13 @@ describe("Counting Repetition - howManyTimes", function() {
239238
});
240239
});
241240

242-
describe("Bonus Quest - greatestProduct", function() {
243-
it("Defines greatestProduct", function() {
241+
describe("Bonus Quest - greatestProduct", ()=> {
242+
it("Defines greatestProduct", ()=> {
244243
expect(typeof greatestProduct).toBe("function");
245244
});
246245

247-
it("Return 1 when all the numbers of the arrays are 1", function() {
248-
var matrix = [
246+
it("Return 1 when all the numbers of the arrays are 1", ()=> {
247+
let matrix = [
249248
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
250249
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
251250
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
@@ -270,8 +269,8 @@ describe("Bonus Quest - greatestProduct", function() {
270269
expect(greatestProduct(matrix)).toBe(1);
271270
});
272271

273-
it("Return 16 when all the numbers of the arrays are 2", function() {
274-
var matrix = [
272+
it("Return 16 when all the numbers of the arrays are 2", ()=> {
273+
let matrix = [
275274
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
276275
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
277276
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /