-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenges.js
158 lines (151 loc) · 2.87 KB
/
challenges.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
function getChallenges() {
return [
{
title: 'Renaming a function',
type: 'refactor',
description: 'Select the function name and re-type',
start:
`
function getItems() {
}
`,
end:
`
function getPosts() {
}
`
},
{
title: 'Converting a function to fat arrow',
type: 'refactor',
description: 'Select the `function` text and erase, then use the keyboard to move over and add the fat arrow',
start:
`
const checkStatus = function () {
}
`,
end:
`
const checkStatus = () => {
}
`
},
{
title: 'Duplicate and change',
type: 'refactor',
actions: ['cut-copy-paste'],
description: 'Duplicate the line and swap out the word `section`',
start:
`
$container.classList.add('section')
`,
end:
`
$container.classList.add('section')
$container.classList.add('game-challenge')
`
},
{
title: 'Destructuring an Object',
type: 'refactor',
description: `Convert the longer property name to a destructured variable`,
start:
`
console.log(data.result.user.name)
`,
end:
`
const { user } = data.result
console.log(user.name)
`
},
{
title: 'Destructuring an Array',
type: 'refactor',
description: `Convert the longer property name to a destructured variable`,
start:
`
const firstName = name[0]
const lastName = name[1]
console.log(firstName, lastName)
`,
end:
`
const [firstName, lastName] = name
console.log(firstName, lastName)
`
},
{
title: 'Extract a variable',
type: 'refactor',
description: `Extract the object into its own variable`,
start:
`
response.json({
error: {
message: 'Something went wrong'
}
})
`,
end:
`
const data = {
error: {
message: 'Something went wrong'
}
}
response.json(data)
`
},
{
title: 'Extract a DOM node',
type: 'refactor',
description: `Store a DOM node to a reusable variable`,
width: 'is-7',
start:
`
document.querySelector('.btn').classList.add('loading')
document.querySelector('.btn').innerText = 'LOADING...'
`,
end:
`
const $btn = document.querySelector('.btn')
$btn.classList.add('loading')
$btn.innerText = 'LOADING...'
`
},
{
title: 'Shorten a fat arrow function to a single line',
type: 'refactor',
description: `Change the Higher-Order Function to a single-line fat arrow`,
start:
`
cohorts.filter(function (cohort) {
return cohort.students.length > 20
})
`,
end:
`
cohorts.filter(cohort => cohort.students.length > 20)
`
},
{
title: 'Extract a Higher-Order Function',
type: 'refactor',
description: `Extract the anonymous function into its own named function`,
start:
`
images.filter(function (image) {
return image.size <= 100
})
`,
end:
`
function filterBySize(image) {
return image.size <= 100
}
images.filter(filterBySize)
`
}
]
}