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

Skip to content

Commit d93804a

Browse files
committed
Added ES6 project for bug challenge
1 parent 3b1be7e commit d93804a

File tree

6,785 files changed

+589974
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,785 files changed

+589974
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["es2015", "stage-1"],
3+
"compact": true
4+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import BugChallenge from '../bug-challenge';
2+
import '../jest-helpers';
3+
4+
const challenge = new BugChallenge();
5+
6+
describe('Bug challenge ES6', () => {
7+
8+
beforeEach(() => {
9+
console.clear();
10+
});
11+
12+
describe('bug1', () => {
13+
14+
it("should list the names and ages of people", () => {
15+
challenge.bug1();
16+
17+
expect(console.logs).toEqual([
18+
"Alice is 25",
19+
"Bob is 27",
20+
"Charlie is 40"
21+
]);
22+
});
23+
24+
});
25+
26+
describe('bug2', () => {
27+
28+
it("should list all items in the array in reverse order", () => {
29+
challenge.bug2();
30+
31+
expect(console.logs).toEqual([
32+
'4',
33+
'3',
34+
'2',
35+
'1'
36+
]);
37+
});
38+
39+
});
40+
41+
describe('bug3', () => {
42+
43+
it("should output the total of the indices (0 + 1 + 2 = 3)", () => {
44+
challenge.bug3();
45+
46+
expect(console.logs).toEqual([
47+
'3'
48+
]);
49+
});
50+
51+
});
52+
53+
describe('bug4', () => {
54+
55+
it("should list all movies and actors, except the top 3", () => {
56+
challenge.bug4();
57+
58+
expect(console.logs).toEqual([
59+
'movie: Pulp Fiction',
60+
'movie: Fight club',
61+
'movie: Forrest Gump',
62+
'movie: Inception',
63+
'movie: Goodfellas',
64+
'movie: The Matrix',
65+
'movie: Interstellar',
66+
'actor: Al Pacino',
67+
'actor: Daniel Day-Lewis',
68+
'actor: Duston Hoffman',
69+
'actor: Tom Hanks',
70+
'actor: Anthony Hopkins',
71+
'actor: Paul Newman',
72+
'actor: Denzel Washington'
73+
]);
74+
});
75+
76+
});
77+
78+
describe('bug5', () => {
79+
80+
it("should fetch with caching disabled", () => {
81+
challenge.bug5();
82+
83+
expect(console.logs).toEqual([
84+
'fetch: GET http://www.example.com (useCaching=false)'
85+
]);
86+
});
87+
88+
});
89+
90+
describe('bug6', () => {
91+
92+
it("should run main.js", () => {
93+
challenge.bug6();
94+
95+
expect(console.logs).toEqual([
96+
'run: script=main.js'
97+
]);
98+
});
99+
100+
});
101+
102+
describe('bug7', () => {
103+
104+
it("should first run with stopOnError=all and then with stopOnError=null", () => {
105+
challenge.bug6();
106+
107+
expect(console.logs).toEqual([
108+
'run: stopOnError=all',
109+
'run: stopOnError=null'
110+
]);
111+
});
112+
113+
});
114+
115+
116+
describe('bug8', () => {
117+
118+
it("should lists numbers 1 through 6", () => {
119+
challenge.bug8();
120+
jest.runAllTimers();
121+
122+
expect(console.logs).toEqual([
123+
'1',
124+
'2',
125+
'3',
126+
'4',
127+
'5'
128+
]);
129+
});
130+
131+
});
132+
133+
});
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
export default class BugChallenge {
2+
3+
//------
4+
// Bugs
5+
6+
bug1() {
7+
const people = [{
8+
name: 'Alice',
9+
age: 25
10+
}, {
11+
name: 'Bob',
12+
age: 27
13+
}, {
14+
name: 'Charlie',
15+
age: 40
16+
}];
17+
18+
for (let person in people) {
19+
console.log(`${person.name} is ${person.age}`);
20+
}
21+
}
22+
23+
bug2() {
24+
const array = [1, 2, 3, 4];
25+
26+
for (let i = 0; i < array.length; i++) {
27+
console.log(array.pop());
28+
}
29+
}
30+
31+
bug3() {
32+
const array = {};
33+
array[0] = 'a';
34+
array[1] = 'b';
35+
array[2] = 'c';
36+
37+
let total = 0;
38+
for (let key in obj) {
39+
total += key;
40+
}
41+
42+
console.log(total);
43+
}
44+
45+
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+
// We list all movies, except the top 3.
73+
var index = 3;
74+
for (index; index < top10Movies.length; index++) {
75+
console.log(`movie: ${top10Movies[index]}`);
76+
}
77+
78+
// We also list all actors, except the top 3.
79+
for (index; index < top10Actors.length; index++) {
80+
console.log(`actor: ${top10Actors[index]}`);
81+
}
82+
}
83+
84+
bug5() {
85+
const defaultMethod = 'GET';
86+
const defaultUseCaching = true;
87+
88+
function fetch(options) {
89+
const url = options.url;
90+
const method = options.method || defaultMethod;
91+
const useCaching = options.useCaching || defaultUseCaching;
92+
93+
console.log(`fetch: ${method} ${url} (useCaching=${useCaching})`);
94+
}
95+
96+
fetch({
97+
url: 'http://www.example.com',
98+
useCaching: false
99+
});
100+
}
101+
102+
bug6() {
103+
function run(options) {
104+
if (options.script == undefined) {
105+
options.script = 'main.js';
106+
}
107+
108+
console.log(`run: script=${options.script}`);
109+
}
110+
111+
run();
112+
}
113+
114+
bug7() {
115+
function run(options = {}) {
116+
if (options.stopOnError == undefined) {
117+
options.stopOnError = 'all';
118+
}
119+
120+
console.log(`run: stopOnError=${options.stopOnError}`);
121+
}
122+
123+
run();
124+
run({stopOnError: null});
125+
}
126+
127+
bug8() {
128+
for (var i = 0; i < 5; i++) {
129+
setTimeout(function () {
130+
console.log(i+1);
131+
}, 100*i);
132+
}
133+
}
134+
135+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
jest.useFakeTimers();
2+
3+
console.logs = [];
4+
5+
console.clear = function() {
6+
console.logs = [];
7+
}
8+
console.log = function(message) {
9+
console.logs.push(message.toString());
10+
}

fundamentals/bug-challenge-es6/node_modules/.bin/acorn

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/babylon

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/cdl

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/errno

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/escodegen

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/esgenerate

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/esparse

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/esvalidate

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/handlebars

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/har-validator

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/istanbul

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/jest

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/jest-runtime

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/js-yaml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/jsesc

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/json5

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/loose-envify

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/marked

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/mkdirp

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/nopt

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/notify

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/regjsparser

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/rimraf

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/sane

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/semver

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/sshpk-conv

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/sshpk-sign

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/sshpk-verify

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/uglifyjs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/uuid

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/.bin/which

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fundamentals/bug-challenge-es6/node_modules/abab/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)