|
1 | 1 | 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 | + ] |
3 | 29 | //------ |
4 | 30 | // Bugs |
5 | 31 |
|
@@ -43,41 +69,15 @@ export default class BugChallenge { |
43 | 69 | } |
44 | 70 |
|
45 | 71 | 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 | | - |
72 | 72 | // We list all movies, except the top 3. |
73 | 73 | 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]}`); |
76 | 76 | } |
77 | 77 |
|
78 | 78 | // We also list all actors, except the top 3. |
79 | 79 | for (index; index < top10Actors.length; index++) { |
80 | | - console.log(`actor: ${top10Actors[index]}`); |
| 80 | + console.log(`actor: ${this.top10Actors[index]}`); |
81 | 81 | } |
82 | 82 | } |
83 | 83 |
|
@@ -204,5 +204,34 @@ export default class BugChallenge { |
204 | 204 | console.log(`y=${y}`); |
205 | 205 | } |
206 | 206 |
|
| 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 | + } |
207 | 236 |
|
208 | 237 | } |
0 commit comments