Skip to content

Commit 47f5400

Browse files
committed
code
0 parents  commit 47f5400

File tree

187 files changed

+9570
-0
lines changed

Some content is hidden

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

187 files changed

+9570
-0
lines changed

.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["env"],
3+
"plugins": ["transform-async-to-generator", "transform-object-rest-spread", "transform-class-properties"],
4+
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
code/functions/arrow/close.js

.eslintrc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"env": {
3+
"browser": true
4+
},
5+
"parser": "babel-eslint",
6+
"extends": "airbnb",
7+
"globals": {
8+
"document": true,
9+
"afterEach": true,
10+
"beforeEach": true,
11+
"jest": true,
12+
"it": true,
13+
"describe": true,
14+
"expect": true,
15+
"fetch": true,
16+
"google": true
17+
},
18+
"rules": {
19+
"class-methods-use-this": 0,
20+
"no-restricted-syntax": 0,
21+
"import/prefer-default-export": 0,
22+
"no-underscore-dangle": 0,
23+
"no-unused-expressions": 0,
24+
"no-plusplus": 0,
25+
"no-shadow": 0,
26+
"arrow-parens": ["error", "as-needed"],
27+
"arrow-body-style": 0,
28+
"linebreak-style": "off"
29+
}
30+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

code/arrays/arrays/arrays.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* eslint-disable no-restricted-syntax */
2+
3+
// # START:sort
4+
const team = [
5+
'Joe',
6+
'Dyan',
7+
'Bea',
8+
'Theo',
9+
];
10+
11+
function alphabetizeTeam(team) {
12+
return [...team].sort();
13+
// ['Bea', 'Dyan', 'Joe', 'Theo']
14+
}
15+
// # END:sort
16+
17+
function getTotalStats() {
18+
// # START:loop
19+
20+
const game1 = {
21+
player: 'Jim Jonas',
22+
hits: 2,
23+
runs: 1,
24+
errors: 0,
25+
};
26+
27+
const game2 = {
28+
player: 'Jim Jonas',
29+
hits: 3,
30+
runs: 0,
31+
errors: 1,
32+
};
33+
34+
const total = {};
35+
36+
const stats = Object.keys(game1);
37+
for (let i = 0; i < stats.length; i++) {
38+
const stat = stats[i];
39+
if (stat !== 'player') {
40+
total[stat] = game1[stat] + game2[stat];
41+
}
42+
}
43+
44+
// {
45+
// hits: 5,
46+
// runs: 1,
47+
// errors: 1
48+
// }
49+
50+
// # END:loop
51+
return total;
52+
}
53+
54+
// # START:filter
55+
const staff = [
56+
{
57+
name: 'Wesley',
58+
position: 'musician',
59+
},
60+
{
61+
name: 'Davis',
62+
position: 'engineer',
63+
},
64+
];
65+
66+
function getMusicians(staff) {
67+
return staff.filter(member => member.position === 'musician');
68+
// [{name: 'Wesley', position: 'musician'}]
69+
}
70+
// # END:filter
71+
72+
// # START:object
73+
const dog = {
74+
name: 'Don',
75+
color: 'black',
76+
};
77+
78+
dog.name;
79+
// Don
80+
81+
// # END:object
82+
83+
// # START:pair
84+
const dogPair = [
85+
['name', 'Don'],
86+
['color', 'black'],
87+
];
88+
89+
function getName(dog) {
90+
return dog.find(attribute => {
91+
return attribute[0] === 'name';
92+
})[1];
93+
}
94+
// # END:pair
95+
96+
export {
97+
alphabetizeTeam,
98+
dogPair,
99+
getMusicians,
100+
getName,
101+
getTotalStats,
102+
staff,
103+
team,
104+
};

code/arrays/arrays/arrays.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import expect from 'expect';
2+
import {
3+
alphabetizeTeam,
4+
dogPair,
5+
getMusicians,
6+
getName,
7+
getTotalStats,
8+
staff,
9+
team,
10+
} from './arrays';
11+
12+
describe('array actions', () => {
13+
it('should alphabetize team', () => {
14+
expect(alphabetizeTeam(team)).toEqual([
15+
'Bea',
16+
'Dyan',
17+
'Joe',
18+
'Theo',
19+
]);
20+
});
21+
22+
it('should get musicians', () => {
23+
expect(getMusicians(staff)).toEqual([
24+
{
25+
name: 'Wesley',
26+
position: 'musician',
27+
},
28+
]);
29+
});
30+
31+
it('should get name', () => {
32+
expect(getName(dogPair)).toEqual('Don');
33+
});
34+
35+
it('should calculate stats', () => {
36+
expect(getTotalStats()).toEqual({
37+
hits: 5,
38+
runs: 1,
39+
errors: 1,
40+
});
41+
});
42+
});

code/arrays/includes/greater.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-disable no-unused-vars */
2+
3+
// # START:index
4+
const sections = ['contact', 'shipping'];
5+
6+
function displayShipping(sections) {
7+
return sections.indexOf('shipping') > -1;
8+
}
9+
10+
// true
11+
12+
// # END:index
13+
14+
export { displayShipping };

code/arrays/includes/includes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* eslint-disable no-unused-vars */
2+
3+
// # START:includes
4+
const sections = ['contact', 'shipping'];
5+
6+
function displayShipping(sections) {
7+
return sections.includes('shipping');
8+
}
9+
// # END:includes
10+
11+
export { displayShipping };
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import expect from 'expect';
2+
import {
3+
displayShipping,
4+
} from './includes';
5+
6+
import {
7+
displayShipping as displayShippingIndex,
8+
} from './greater';
9+
10+
describe('includes actions', () => {
11+
it('should display shipping using index', () => {
12+
const sections = ['shipping', 'address'];
13+
expect(displayShippingIndex(sections)).toEqual(true);
14+
});
15+
16+
it('should not display shipping using index', () => {
17+
const sections = ['contact', 'address'];
18+
expect(displayShippingIndex(sections)).toEqual(false);
19+
});
20+
21+
it('should display shipping', () => {
22+
const sections = ['shipping', 'address'];
23+
expect(displayShipping(sections)).toEqual(true);
24+
});
25+
26+
it('should not display shipping', () => {
27+
const sections = ['contact', 'address'];
28+
expect(displayShipping(sections)).toEqual(false);
29+
});
30+
});

code/arrays/includes/problem.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* eslint-disable no-unused-vars */
2+
// # START:noIndex
3+
const sections = ['shipping'];
4+
5+
function displayShipping(sections) {
6+
if (sections.indexOf('shipping')) {
7+
return true;
8+
}
9+
return false;
10+
}
11+
12+
// false
13+
14+
// # END:noIndex
15+
16+
export { displayShipping };

0 commit comments

Comments
 (0)