-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
242 lines (225 loc) · 7.72 KB
/
index.js
File metadata and controls
242 lines (225 loc) · 7.72 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// ⭐️ Example Challenge start ⭐️
/**
* ### Challenge `exampleFunction`
*
* @instructions
* This function should be able to take two numbers as arguments
* and return the result of adding them together.
*
* For example, if we invoke `exampleFunction` passing 5 and 3,
* the returned value should be 8.
*/
function exampleFunction(num1, num2) {
return num1 + num2;
}
// ⭐️ Example Challenge end ⭐️
// 👇 COMPLETE YOUR WORK BELOW 👇
// 👇 COMPLETE YOUR WORK BELOW 👇
// 👇 COMPLETE YOUR WORK BELOW 👇
/**
* ### Challenge `makePersonObject`
*
* @instructions
* This function should take an id, a name and an email as arguments,
* and return an object with `id`, `name` and `email` properties.
*
* For example, if we invoke `makePersonObject`
* passing 5, 'Leia' and 'leia@leia.com' as arguments,
* the returned value should look like:
* {
* id: 5,
* name: "Leia",
* email: "leia@leia.com",
* }
*/
function makePersonObject(/* code here */) {
/* code here */
}
/**
* ### Challenge `getName`
*
* @instructions
* This function takes as its only argument
* an object containing a `name` property,
* and return a string that reads `Hello, my name is {name}`,
* where `{name}` is the name stored in the object.
*
* For example, if we invoke `getName`
* passing { id: 1, name: 'Leia', email: 'leia@leia.com` } as the argument,
* the returned value should look like `Hello, my name is Leia`.
*/
function getName(/* code here */) {
/* code here */
}
/**
* ### Challenge `makeSmartPerson`
*
* @instructions
* This function takes a single `name` argument and returns an object.
* The returned object has the following characteristics:
* It has a `name` property that contains the argument passed in.
* It has a `sum` method that takes two numbers as arguments
* and returns the result of adding them together.
* It has a `speak` method that takes no arguments
* and returns a string like `Hello, my name is {name}`.
* where `{name}` is the name passed into `makeSmartPerson`.
*/
function makeSmartPerson(/* code here */) {
/* code here */
}
/**
* ### Challenge `getCarInfoByIndex`
*
* @instructions
* getCarInfoByIndex takes two arguments:
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* (2) a number which is the desired index in the array.
* getCarInfoByIndex returns a string in the format `This is a {car_make} {car_model}
*
* For example, if getCarInfoByIndex is invoked with the inventory and the number 0,
* it will return `This is a Lincoln Navigator`.
*/
function getCarInfoByIndex(/* code here */) {
/* code here */
}
/**
* ### Challenge `getLastCarInfo`
*
* @instructions
* getLastCarInfo takes a single argument:
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* getLastCarInfo returns a string in the format `This is a {car_make} {car_model}
*
* For example, if getLastCarInfo is invoked passing the inventory inside /data/inventory.js,
* it will return `This is a Lincoln Town Car`.
*/
function getLastCarInfo(/* code here */) {
/* code here */
}
/**
* ### Challenge `getCarInfoById`
*
* @instructions
* getCarInfoById takes two arguments:
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* (2) a number which is the desired car id (see how each car has its own unique id).
* getCarInfoById returns a string in the format `This is a {car_make} {car_model}
*
* For example, if getCarInfoById is invoked with the inventory and the number 1,
* it will return `This is a Lincoln Navigator`.
*/
function getCarInfoById(/* code here */) {
/* code here */
}
/**
* ### Challenge `sortCarInventory`
*
* @instructions
* sortCarInventory takes a single argument:
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* sortCarInventory returns an inventory that is sorted by car_model, ascending [A-Z].
*/
function sortCarInventory(/* code here */) {
/* code here */
}
/**
* ### Challenge `getModelYears`
*
* @instructions
* We need the years from every car in the inventory!
* getModelYears takes a single argument:
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* getModelYears returns an array containing all the 'car_year's in the inventory.
*/
function getModelYears(/* code here */) {
/* code here */
}
/**
* ### Challenge `getOlderCars`
*
* @instructions
* We need a utility to find older cars!
* getOlderCars takes two arguments:
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* (2) a number which is the desired max year.
* getOlderCars returns an array containing all the cars
* with a `car_year` which is at most the given desired max year,
* in the same order as they appear in the original inventory.
*/
function getOlderCars(/* code here */) {
/* code here */
}
/**
* ### Challenge `getGermanCars`
*
* @instructions
* We need a utility to find German cars!
* getGermanCars takes a single argument:
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* getGermanCars returns an array containing all the cars
* made by either `Audi` or `Mercedes-Benz` or `Volkswagen` or `BMW`,
* in the same order as they appear in the original inventory.
*/
function getGermanCars(/* code here */) {
/* code here */
}
/**
* ### Challenge refactor to arrow functions
*
* @instructions
* Create arrow function versions of the following commented-out functions:
*
* const sum = function (a, b) {
* return a + b
* }
*
* const addFive = function(num) {
* return num + 5
* }
*
* const argTimesTwo = function (num) {
* return num * 2
* }
*/
const sum = null; // code here!
const addFive = null; // code here!
const argTimesTwo = null; // code here!
/**
* ### Challenge `carMaker`
* THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER
* COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY!
*
* @instructions
* This function takes a single odometer argument (a number) and returns an object.
* The returned object has the following characteristics:
* it has an `odometer` property that contains the argument passed in.
* it has a `drive` method that takes a distance as its argument, and
* (1) causes the odometer in the object to be increased by the distance,
* (2) returns the updated value of the `odometer`.
*/
function carMaker(/* code here */) {
/* code here */
}
/// ////// END OF CHALLENGE /////////
/// ////// END OF CHALLENGE /////////
/// ////// END OF CHALLENGE /////////
if (typeof exports !== 'undefined') {
// IGNORE: Test/Env Detected
// For Node/Non-browser test env
module.exports = module.exports || {}
if (exampleFunction) { module.exports.exampleFunction = exampleFunction }
if (makePersonObject) { module.exports.makePersonObject = makePersonObject }
if (getName) { module.exports.getName = getName }
if (makeSmartPerson) { module.exports.makeSmartPerson = makeSmartPerson }
if (carMaker) { module.exports.carMaker = carMaker }
if (getCarInfoByIndex) { module.exports.getCarInfoByIndex = getCarInfoByIndex }
if (getLastCarInfo) { module.exports.getLastCarInfo = getLastCarInfo }
if (getCarInfoById) { module.exports.getCarInfoById = getCarInfoById }
if (sortCarInventory) { module.exports.sortCarInventory = sortCarInventory }
if (getModelYears) { module.exports.getModelYears = getModelYears }
if (getOlderCars) { module.exports.getOlderCars = getOlderCars }
if (getGermanCars) { module.exports.getGermanCars = getGermanCars }
if (sum) { module.exports.sum = sum }
if (addFive) { module.exports.addFive = addFive }
if (argTimesTwo) { module.exports.argTimesTwo = argTimesTwo }
}