Skip to content

Commit 30e1c10

Browse files
committed
no undefined
1 parent aa6490c commit 30e1c10

File tree

1 file changed

+138
-86
lines changed

1 file changed

+138
-86
lines changed

starter-code/tests/FunctionsAndArraysSpec.js

+138-86
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/* eslint no-undef: 'off' */
21
function shuffle(currentArray) {
3-
var array = currentArray.map(function (arr) {
2+
var array = currentArray.map(function(arr) {
43
return arr.slice();
54
});
65
var counter = array.length;
@@ -13,185 +12,239 @@ function shuffle(currentArray) {
1312
}
1413
return array;
1514
}
16-
describe('Find the maximum - maxOfTwoNumbers', function () {
17-
it('Defines maxOfTwoNumbers', function () {
18-
expect(typeof maxOfTwoNumbers).toBe('function');
15+
describe("Find the maximum - maxOfTwoNumbers", function() {
16+
it("Defines maxOfTwoNumbers", function() {
17+
expect(typeof maxOfTwoNumbers).toBe("function");
1918
});
2019

21-
it('First parameter larger', function () {
20+
it("First parameter larger", function() {
2221
expect(maxOfTwoNumbers(2, 1)).toBe(2);
2322
});
2423

25-
it('Second parameter larger', function () {
24+
it("Second parameter larger", function() {
2625
expect(maxOfTwoNumbers(1, 3)).toBe(3);
2726
});
2827

29-
it('First and Second parameter equal', function () {
28+
it("First and Second parameter equal", function() {
3029
expect(maxOfTwoNumbers(4, 4)).toBe(4);
3130
});
3231
});
3332

34-
describe('Finding Longest Word - findLongestWord', function () {
35-
it('Defines findLongestWord', function () {
36-
expect(typeof findLongestWord).toBe('function');
33+
describe("Finding Longest Word - findLongestWord", function() {
34+
it("Defines findLongestWord", function() {
35+
expect(typeof findLongestWord).toBe("function");
3736
});
3837

39-
it('returns undefined with an empty array', function () {
40-
expect(findLongestWord([])).toBe(undefined);
38+
it("returns null with an empty array", function() {
39+
expect(findLongestWord([])).toBe(null);
4140
});
4241

43-
it('returns the word with an 1-word array', function () {
44-
expect(findLongestWord(['foo'])).toBe('foo');
42+
it("returns the word with an 1-word array", function() {
43+
expect(findLongestWord(["foo"])).toBe("foo");
4544
});
4645

47-
it('returns the first occurrence word when longest have multiple occurrences ', function () {
48-
expect(findLongestWord(['foo', 'bar'])).toBe('foo');
49-
expect(findLongestWord(['bar', 'foo'])).toBe('bar');
46+
it("returns the first occurrence word when longest have multiple occurrences ", function() {
47+
expect(findLongestWord(["foo", "bar"])).toBe("foo");
48+
expect(findLongestWord(["bar", "foo"])).toBe("bar");
5049
});
5150

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

61-
describe('Calculating a Sum - sumArray', function () {
62-
it('Defines sumArray', function () {
63-
expect(typeof sumArray).toBe('function');
60+
describe("Calculating a Sum - sumArray", function() {
61+
it("Defines sumArray", function() {
62+
expect(typeof sumArray).toBe("function");
6463
});
6564

66-
it('returns zero with an empty array', function () {
65+
it("returns zero with an empty array", function() {
6766
expect(sumArray([])).toBe(0);
6867
});
6968

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

74-
it('returns zero if all elements are zero', function () {
73+
it("returns zero if all elements are zero", function() {
7574
expect(sumArray([0, 0, 0, 0, 0])).toBe(0);
7675
});
7776

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

83-
describe('Calculating the Average - averageNumbers', function () {
84-
it('Defines averageNumbers', function () {
85-
expect(typeof averageNumbers).toBe('function');
82+
describe("Calculating the Average - averageNumbers", function() {
83+
it("Defines averageNumbers", function() {
84+
expect(typeof averageNumbers).toBe("function");
8685
});
8786

88-
it('returns undefined with an empty array', function () {
89-
expect(averageNumbers([])).toBe(undefined);
87+
it("returns null with an empty array", function() {
88+
expect(averageNumbers([])).toBe(null);
9089
});
9190

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

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

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

105-
describe('Calculating the Average - averageWordLength', function () {
106-
it('Defines averageWordLength', function () {
107-
expect(typeof averageWordLength).toBe('function');
104+
describe("Calculating the Average - averageWordLength", function() {
105+
it("Defines averageWordLength", function() {
106+
expect(typeof averageWordLength).toBe("function");
108107
});
109108

110-
it('returns undefined with an empty array', function () {
111-
expect(averageWordLength([])).toBe(undefined);
109+
it("returns null with an empty array", function() {
110+
expect(averageWordLength([])).toBe(null);
112111
});
113112

114-
it('returns the average of a unique element array', function () {
115-
expect(averageWordLength(['ironhack'])).toBe(8);
113+
it("returns the average of a unique element array", function() {
114+
expect(averageWordLength(["ironhack"])).toBe(8);
116115
});
117116

118-
it('returns the average of a the array', function () {
119-
expect(averageWordLength(['Ironhack', 'Madrid', 'Barcelona', 'Paris', 'Miami', 'Mexico', 'Berlin', 'Programmers'])).toBe(7);
117+
it("returns the average of a the array", function() {
118+
expect(
119+
averageWordLength([
120+
"Ironhack",
121+
"Madrid",
122+
"Barcelona",
123+
"Paris",
124+
"Miami",
125+
"Mexico",
126+
"Berlin",
127+
"Programmers"
128+
])
129+
).toBe(7);
120130
});
121131
});
122132

123-
describe('Unique Arrays - uniquifyArray', function () {
124-
it('Defines uniquifyArray', function () {
125-
expect(typeof uniquifyArray).toBe('function');
133+
describe("Unique Arrays - uniquifyArray", function() {
134+
it("Defines uniquifyArray", function() {
135+
expect(typeof uniquifyArray).toBe("function");
126136
});
127137

128-
it('returns undefined with an empty array', function () {
129-
expect(uniquifyArray([])).toBe(undefined);
138+
it("returns null with an empty array", function() {
139+
expect(uniquifyArray([])).toBe(null);
130140
});
131141

132-
it('returns the correct array when having an array of the same element', function () {
133-
expect(uniquifyArray(['Ironhack', 'Ironhack', 'Ironhack'])).toEqual(['Ironhack']);
142+
it("returns the correct array when having an array of the same element", function() {
143+
expect(uniquifyArray(["Ironhack", "Ironhack", "Ironhack"])).toEqual([
144+
"Ironhack"
145+
]);
134146
});
135147

136-
it('returns the same array when no element is repeated', function () {
137-
expect(uniquifyArray(['Cat', 'Dog', 'Cow'])).toEqual(['Cat', 'Dog', 'Cow']);
148+
it("returns the same array when no element is repeated", function() {
149+
expect(uniquifyArray(["Cat", "Dog", "Cow"])).toEqual(["Cat", "Dog", "Cow"]);
138150
});
139151

140-
it('returns the uniquified array', function () {
141-
expect(uniquifyArray(['iPhone', 'Samsung', 'Android', 'iOS', 'iPhone', 'Samsung', 'Nokia', 'Blackberry', 'Android'])).toEqual(['iPhone', 'Samsung', 'Android', 'iOS', 'Nokia', 'Blackberry']);
152+
it("returns the uniquified array", function() {
153+
expect(
154+
uniquifyArray([
155+
"iPhone",
156+
"Samsung",
157+
"Android",
158+
"iOS",
159+
"iPhone",
160+
"Samsung",
161+
"Nokia",
162+
"Blackberry",
163+
"Android"
164+
])
165+
).toEqual(["iPhone", "Samsung", "Android", "iOS", "Nokia", "Blackberry"]);
142166
});
143167
});
144168

145-
describe('Finding Elements - doesWordExist', function () {
146-
it('Defines doesWordExist', function () {
147-
expect(typeof doesWordExist).toBe('function');
169+
describe("Finding Elements - doesWordExist", function() {
170+
it("Defines doesWordExist", function() {
171+
expect(typeof doesWordExist).toBe("function");
148172
});
149173

150-
it('returns false with an empty array', function () {
174+
it("returns false with an empty array", function() {
151175
expect(doesWordExist([])).toBe(false);
152176
});
153177

154-
it('returns true if the word we are looking is the only one on the array', function () {
155-
expect(doesWordExist(['machine'], 'machine')).toBe(true);
178+
it("returns true if the word we are looking is the only one on the array", function() {
179+
expect(doesWordExist(["machine"], "machine")).toBe(true);
156180
});
157181

158-
it('returns false if the word we are looking is not in the array', function () {
159-
expect(doesWordExist(['machine', 'poison', 'eat', 'apple', 'horse'], 'ratatouille')).toBe(false);
182+
it("returns false if the word we are looking is not in the array", function() {
183+
expect(
184+
doesWordExist(
185+
["machine", "poison", "eat", "apple", "horse"],
186+
"ratatouille"
187+
)
188+
).toBe(false);
160189
});
161190

162-
it('returns true if the word we are looking is in the array', function () {
163-
expect(doesWordExist(['pizza', 'sandwich', 'snack', 'soda', 'book', 'computer'], 'book')).toBe(true);
191+
it("returns true if the word we are looking is in the array", function() {
192+
expect(
193+
doesWordExist(
194+
["pizza", "sandwich", "snack", "soda", "book", "computer"],
195+
"book"
196+
)
197+
).toBe(true);
164198
});
165199
});
166200

167-
describe('Counting Repetition - howManyTimes', function () {
168-
it('Defines howManyTimes', function () {
169-
expect(typeof howManyTimes).toBe('function');
201+
describe("Counting Repetition - howManyTimes", function() {
202+
it("Defines howManyTimes", function() {
203+
expect(typeof howManyTimes).toBe("function");
170204
});
171205

172-
it('returns false with an empty array', function () {
206+
it("returns false with an empty array", function() {
173207
expect(howManyTimes([])).toBe(false);
174208
});
175209

176-
it('returns one when the word appears only one time on the array', function () {
177-
expect(howManyTimes(['basketball', 'football', 'tennis'], 'tennis')).toBe(1);
178-
});
179-
180-
it('returns zero when the word does not appears on the array', function () {
181-
expect(howManyTimes(['basketball', 'football', 'tennis'], 'rugby')).toBe(0);
182-
});
183-
184-
it('returns five when the word appears 5 times on the array', function () {
185-
expect(howManyTimes(['basketball', 'football', 'tennis', 'rugby', 'rugby', 'ping pong', 'rugby', 'basketball', 'rugby', 'handball', 'rugby'], 'rugby')).toBe(5);
210+
it("returns one when the word appears only one time on the array", function() {
211+
expect(howManyTimes(["basketball", "football", "tennis"], "tennis")).toBe(
212+
1
213+
);
214+
});
215+
216+
it("returns zero when the word does not appears on the array", function() {
217+
expect(howManyTimes(["basketball", "football", "tennis"], "rugby")).toBe(0);
218+
});
219+
220+
it("returns five when the word appears 5 times on the array", function() {
221+
expect(
222+
howManyTimes(
223+
[
224+
"basketball",
225+
"football",
226+
"tennis",
227+
"rugby",
228+
"rugby",
229+
"ping pong",
230+
"rugby",
231+
"basketball",
232+
"rugby",
233+
"handball",
234+
"rugby"
235+
],
236+
"rugby"
237+
)
238+
).toBe(5);
186239
});
187240
});
188241

189-
describe('Bonus Quest - greatestProduct', function () {
190-
it('Defines greatestProduct', function () {
191-
expect(typeof greatestProduct).toBe('function');
242+
describe("Bonus Quest - greatestProduct", function() {
243+
it("Defines greatestProduct", function() {
244+
expect(typeof greatestProduct).toBe("function");
192245
});
193246

194-
it('Return 1 when all the numbers of the arrays are 1', function () {
247+
it("Return 1 when all the numbers of the arrays are 1", function() {
195248
var matrix = [
196249
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
197250
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
@@ -217,7 +270,7 @@ describe('Bonus Quest - greatestProduct', function () {
217270
expect(greatestProduct(matrix)).toBe(1);
218271
});
219272

220-
it('Return 16 when all the numbers of the arrays are 2', function () {
273+
it("Return 16 when all the numbers of the arrays are 2", function() {
221274
var matrix = [
222275
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
223276
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
@@ -243,4 +296,3 @@ describe('Bonus Quest - greatestProduct', function () {
243296
expect(greatestProduct(matrix)).toBe(16);
244297
});
245298
});
246-

0 commit comments

Comments
 (0)