Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3385406

Browse files
added a few more bugs
1 parent 828ac51 commit 3385406

File tree

3 files changed

+107
-31
lines changed

3 files changed

+107
-31
lines changed

fundamentals/bug-challenge-es6/__tests__/bug-challenge-tests.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,49 @@ describe('Bug challenge ES6', () => {
180180
});
181181

182182
});
183+
describe('bug13', () => {
184+
it("should return that AI, Godfather and Inception are in the top10 movie list", () => {
185+
challenge.bug13();
186+
jest.runAllTimers();
187+
188+
expect(console.logs).toEqual([
189+
"Independence Day is not in the top 10!",
190+
"AI is in the top 10!",
191+
"Godfather is in the top 10!",
192+
"Inception is in the top 10!"
193+
]);
194+
});
195+
196+
});
197+
describe('bug14', () => {
198+
it("should return that AI is best movie ever", () => {
199+
challenge.bug14();
200+
jest.runAllTimers();
201+
202+
expect(console.logs).toEqual([
203+
"AI is best movie ever",
204+
"Godfather is not best movie ever",
205+
]);
206+
});
207+
});
208+
describe('bug15', () => {
209+
it("should return Al Pacino as first actor after sorting alphabetically", () => {
210+
challenge.bug15();
211+
jest.runAllTimers();
212+
213+
expect(console.logs).toEqual([
214+
'The first actor when sorted alphabetically is Al Pacino'
215+
]);
216+
});
217+
});
218+
describe('bug16', () => {
219+
it("should return that Al Pacino is ranked 4th among all actors", () => {
220+
challenge.bug16();
221+
jest.runAllTimers();
183222

184-
});
223+
expect(console.logs).toEqual([
224+
'Al Pacino is ranked 4'
225+
]);
226+
});
227+
});
228+
});

fundamentals/bug-challenge-es6/bug-challenge.js

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
export default class BugChallenge {
2-
2+
//Do NOT change the top10Movies and top10Actors variables to fix your tests
3+
//believe me: the problem is in bug() functions, not in these arrays ;)
4+
top10Movies = [
5+
'AI',
6+
'Shawshank Redemption',
7+
'Godfather',
8+
'Pulp Fiction',
9+
'Fight club',
10+
'Forrest Gump',
11+
'Inception',
12+
'Goodfellas',
13+
'The Matrix',
14+
'Interstellar'
15+
]
16+
top10Actors = [
17+
'Marlon Brando',
18+
'Jack Nickolson',
19+
'Robert De Niro',
20+
'Al Pacino',
21+
'Daniel Day-Lewis',
22+
'Duston Hoffman',
23+
'Tom Hanks',
24+
'Anthony Hopkins',
25+
'Paul Newman',
26+
'Denzel Washington'
27+
28+
]
329
//------
430
// Bugs
531

@@ -43,41 +69,15 @@ export default class BugChallenge {
4369
}
4470

4571
bug4() {
46-
const top10Movies = [
47-
'AI',
48-
'Shawshank Redemption',
49-
'Godfather',
50-
'Pulp Fiction',
51-
'Fight club',
52-
'Forrest Gump',
53-
'Inception',
54-
'Goodfellas',
55-
'The Matrix',
56-
'Interstellar'
57-
]
58-
const top10Actors = [
59-
'Marlon Brando',
60-
'Jack Nickolson',
61-
'Robert De Niro',
62-
'Al Pacino',
63-
'Daniel Day-Lewis',
64-
'Duston Hoffman',
65-
'Tom Hanks',
66-
'Anthony Hopkins',
67-
'Paul Newman',
68-
'Denzel Washington'
69-
70-
]
71-
7272
// We list all movies, except the top 3.
7373
var index = 3;
74-
for (index; index < top10Movies.length; index++) {
75-
console.log(`movie: ${top10Movies[index]}`);
74+
for (index; index < this.top10Movies.length; index++) {
75+
console.log(`movie: ${this.top10Movies[index]}`);
7676
}
7777

7878
// We also list all actors, except the top 3.
7979
for (index; index < top10Actors.length; index++) {
80-
console.log(`actor: ${top10Actors[index]}`);
80+
console.log(`actor: ${this.top10Actors[index]}`);
8181
}
8282
}
8383

@@ -204,5 +204,34 @@ export default class BugChallenge {
204204
console.log(`y=${y}`);
205205
}
206206

207+
bug13() {
208+
var notInTop10 = (movieName) => {
209+
return !this.top10Movies.indexOf(movieName)
210+
}
211+
console.log('Independence Day is ' + (notInTop10('Independence Day')?'not ':'') + 'in the top 10!');
212+
console.log('AI is ' + (notInTop10('AI')?'not ':'') + 'in the top 10!');
213+
console.log('Godfather is ' + (notInTop10('Godfather')?'not ':'') + 'in the top 10!');
214+
console.log('Inception is ' + (notInTop10('Inception')?'not ':'') + 'in the top 10!');
215+
}
216+
bug14() {
217+
218+
console.log('AI is ' + (isInFirstPlace('AI')?'':'not ') + 'best movie ever')
219+
console.log('Godfather is ' + (isInFirstPlace('Godfather')?'':'not ') + 'best movie ever')
220+
var isInFirstPlace = (movieName) => {
221+
return this.top10Movies[0] === movieName
222+
}
223+
}
224+
bug15() {
225+
var getAlphabeticalFirst = function() {
226+
return this.top10Actors.sort()[0]
227+
}
228+
229+
console.log(`The first actor when sorted alphabetically is ${getAlphabeticalFirst()}`)
230+
}
231+
bug16() {
232+
const ranking = this.top10Actors.indexOf('Al Pacino');
233+
// var thirdRankedActor = this.top10Actors['2'];
234+
console.log(`Al Pacino is ranked ${ranking + '1'}`)
235+
}
207236

208237
}

fundamentals/bug-challenge-es6/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"/node_modules/"
77
]
88
},
9+
"scripts":{
10+
"test": "jest"
11+
},
912
"devDependencies": {
1013
"babel-core": "^6.18.2",
1114
"babel-jest": "^17.0.2",

0 commit comments

Comments
 (0)