-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
307 lines (238 loc) ยท 10.3 KB
/
index.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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/* โโ REMEMBER TO RETURN ALL OF THE ANSWERS ON THESE TASKS, IF YOU DON'T, THE AUTOGRADER WILL NOT WORK โโ*/
/* ๐ This is your data โฌ */
const originalFlavors = [
"Banana Nut Fudge",
"Black Walnut",
"Burgundy Cherry",
"Butterscotch Ribbon",
"Cherry Macaron",
"Chocolate",
"Chocolate Almond",
"Chocolate Chip",
"Chocolate Fudge",
"Chocolate Mint",
"Chocolate Ribbon",
"Coffee",
"Coffee Candy",
"Date Nut",
"Eggnog",
"French Vanilla",
"Green Mint Stick",
"Lemon Crisp",
"Lemon Custard",
"Lemon Sherbet",
"Maple Nut",
"Orange Sherbet",
"Peach",
"Peppermint Fudge Ribbon",
"Peppermint Stick",
"Pineapple Sherbet",
"Raspberry Sherbet",
"Rocky Road",
"Strawberry",
"Vanilla",
"Vanilla Burnt Almond"
]
/*๐๐๐๐๐๐๐๐๐๐ Task 1: Copy the Array! ๐๐๐๐๐๐๐๐๐๐
We have an array called originalFlavors with 31 flavors (see above). In these tasks, we will be reading and writing data to this array.
With all of these changes going on, we don't want to lose track of the actual, original 31 flavors. So we need to copy the original array!
/*
Use the copy function below to do the following:
1. receive an array as a parameter - you will pass in originalFlavors as an argument when the function is invoked.
2. Return a copy of the received array
*/
function copy(/*your code here*/){
/*your code here*/
}
/*๐๐๐๐๐๐๐๐๐๐ Task 2: ๐๐๐๐๐๐๐๐๐๐
Confirm that an array is exactly 31 flavors. Your function should accept:
1. an array as a parameter
2. Check to see if the array given is 31 flavors
3. Your function should return a boolean TRUE if the length of the array is 31 and FALSE if the length of the array is NOT 31.
For Example: is31Flavors(originalFlavors) will return true if your code is working properly
*/
function is31Flavors(/*your code here*/){
/*your code here*/
}
/* ๐๐๐๐๐๐๐๐๐๐ Task 3: ๐๐๐๐๐๐๐๐๐๐
Corporate has come to you with an idea for a new flavor: Rainbow Sherbert! They think this will be a game changer. You need to modify the array to include this flavor.
Use the addFlavor function below to do the following:
1. Receive an array in the first parameter that will take the flavors array as an argument
2. Receive a string in the second parameter that will take the new flavor as as an argument
3. The function adds the passed flavor to the front of the passed array
4. The function should return the resulting array
For example: addFlavor(originalFlavors, "Rainbow Sherbert") should return the array ["Rainbow Sherbert", "Banana Nut Fudge",..."Vanilla Burnt Almond"]
*/
function addFlavor(/*your code here*/){
/*your code here*/
}
/* ๐๐๐๐๐๐๐๐๐๐ Task 4: ๐๐๐๐๐๐๐๐๐๐
Houston, we have a problem! There are now 32 flavors in the originalFlavors array! Your task is to remove an item from the end of the array.
Use the removeLastFlavor function below to do the following:
1. Receive an array
2. Remove the last item from the received array
3. Return the resulting array
For example: running removeLastFlavor(originalFlavors) would return ["Rainbow Sherbert", "Banana Nut Fudge",..."Vanilla"]
*/
function removeLastFlavor(/*your code here*/){
/*your code here*/
}
/* ๐๐๐๐๐๐๐๐๐๐ Task 5: ๐๐๐๐๐๐๐๐๐๐
Write a function that returns a flavor at a given index in the array.
Use the getFlavorByIndex function below to do the following:
1. Recieve an array in the first parameter that will take the flavors array as an argument
2. Receive a number in the second parameter that will take the the desired index as an argument
3. Return the flavor located at the received index position
For example: running getFlavorByIndex(originalFlavors, 2) would return "Black Walnut", assuming Rainbow Sherbert has been added successfully
*/
function getFlavorByIndex(/*your code here*/){
/*your code here*/
}
/*๐๐๐๐๐๐๐๐๐๐ Task 6: ๐๐๐๐๐๐๐๐๐๐
As corporate wants to add more and more flavors to their lineup, they've realized that they need to remove flavors based on flavor name, as opposed to just arbitrarily removing the first or last flavor. Your task is to get an index by flavor name, and remove that single flavor from the array.
Use the removeFlavorByName function below to do the following:
1. Receive an array in the first parameter that will take the flavors array as an argument
2. Receive a string in the second parameter that will take the flavor name as as an argument
3. Remove the received flavor from the received array
4. Return the resulting array that now contains one less flavor
For example: running removeFlavorByName(originalFlavors, "Rocky Road") would return an array with the a length of 30 because Rocky Road would have been removed.
HINT: You can use .splice() for this
*/
function removeFlavorByName(/*your code here*/){
/*your code here*/
}
/*๐๐๐๐๐๐๐๐๐๐ Task 7: ๐๐๐๐๐๐๐๐๐๐
July 7th is "World Chocolate Day" and Baskin Robins wants to create promotional materials highlighting all of their chocolate flavors.
Your task is to write a function that checks every item in the array for a string and returns a new array called filteredArray with only the values that contain the received string. This would allow you to be able to filter for "Vanilla", "Sherbet", "Lemon" etc. when different holidays roll around by passing in those specific strings.
Use the filterByWord function below to do the following:
1. Receive an array in the first parameter that will take the flavors array as an argument
2. Receive a string in the second parameter that will take the filter value as as an argument (example: "chocolate")
3. Check to see if any of the flavors in the array contain that string
4. If they do, add them to a new array
5. Return the new array that contains the filtered flavors
For example: filterByWord(originalFlavors, "Chocolate") should return ["Chocolate", "Chocolate Almond", "Chocolate Chip", "Chocolate Fudge", "Chocolate Mint", "Chocolate Ribbon"]
HINT - you can use the .includes method to help you solve this
DO NOT USE ADVANCED ARRAY METHODS (i.e. .filter) to solve this problem.
*/
function filterByWord(/*your code here*/){
/*your code here*/
}
/* ๐ช๐ช๐ช๐ช๐ช๐ง๐ฆ๐จ STRETCH ๐จ๐ฆ๐ซ๐ช๐ช๐ช๐ช๐ช*/
/* STRETCH 1: Write a function that returns the average number of words in an array. You should be able to use this function for any array, but can test with originalFlavors.
Use the getAverageWordLength function below to do the following:
1. Receive the originalFlavors array
2. Count how many words per item in the array
3. Return the average number of words per item in the array
For example: getAverageWordLength(originalFlavors) should return a number between 0 and 3.
*/
function getAverageWordLength(/*code here*/){
/*code here*/
}
/* ๐ช๐ช๐ช๐ช๐ช๐ช๐ช๐ช๐ช๐ช STRETCH 2: ๐ช๐ช๐ช๐ช๐ช๐ช๐ช๐ช๐ช
Baskin Robins now offers new flavors, seasonal flavors, and even regional flavors. Write a function that will randomly select a total of 31 flavors
from originalFlavors, currentFlavors, seasonalFlavors, and regionalFlavors and store it in an array called randomFlavors.
Use the getRandomFlavors function and new arrays below to do the following:
1. Receive the four arrays with all the differnet flavors (originalFlavors is above, the others are below)
2. Randomly pick flavors from all four arrays
3. Return a new array called randomFlavors that has a lenght of 31
For example: getRandomFlavors(originalFlavors, newFlavors, seasonalFlavors, regionalFlavors) might return ["Strawberry Cheesecake", "Eggnog,"..."Chocolate"].
*/
function getRandomFlavors(/*code here*/){
/*code here*/
}
// NEW DATA ARRAYS FOR STRETCH 2 โฌ๏ธ
// const newFlavors = [
// "Date night",
// "U.S.S Butterscotch (Stranger Things special)",
// "Honey Almond",
// "Mint Chocolate Chip",
// "Chocolate",
// "Oreoยฎ Cookies'n Cream",
// "Chocolate Chip",
// "Pralines 'n Cream",
// "Very Berry Strawberry",
// "Chocolate Chip Cookie Dough",
// "Old Fashioned Butter Pecan",
// "Jamocaยฎ",
// "Jamocaยฎ Almond Fudge",
// "Reese'sยฎ Peanut Butter Cup",
// "Rocky Road",
// "Peanut Butter โn Chocolate",
// "Gold Medal Ribbonยฎ",
// "World Classยฎ Chocolate",
// "Cherries Jubilee",
// "Chocolate Fudge",
// "Daiquiri Ice",
// "Rainbow Sherbet",
// "Rainbow Swirl"
// ]
// const seasonalFlavors = [
// "America's Birthday Cake",
// "Baseball Nutยฎ",
// "Blueberry Cheesecake",
// "Bourbon Street Pecan Pie",
// "Brownie Bar Mashup",
// "Cherry Cordial with Kisses",
// "Chocolate Mousse Royale",
// "French Vanilla",
// "Eggnog",
// "German Chocolate Cake",
// "Icing on the Cake",
// "Love Potion #31",
// "New York Cheesecake",
// "Nutty Coconut",
// "Peppermint",
// "Strawberry Cheesecake",
// "Rock โn Pop Swirl",
// "Reeseโs Peanut Butter Cup",
// "Trick Oreo Treat",
// "Winter White Chocolate",
// "made with Snickersยฎ",
// "made with M&M'sยฎ",
// "Heathยฎ",
// "Mango Tango"
// ]
// const regionalFlavors = [
// "Pink Bubblegum",
// "Caramel Macchiato",
// "York Peppermint Pattie",
// "Cotton Candy",
// "Orange Sherbet",
// "Grape Ice",
// "Watermelon Ice",
// "Miami Vice Sorbet",
// "Splish Splashยฎ",
// "Wild 'n Reckless Sherbet",
// "Lemon Custard",
// "Oregon Blackberry",
// "Bananas โn Strawberries",
// "Mississippi Mud",
// "Rum Raisin",
// "Creole Cream Cheese",
// "Chocolate Almond",
// "Fudge Brownie",
// "Banana Nut",
// "Black Walnut",
// "Cotton Candy Crackle",
// "Quarterback Crunch",
// "Chocolate Chocolate Chip Cheesecake",
// "Caramel 'n' Cookies"
// ]
/* ๐๐๐๐๐๐๐๐๐๐ Please do not modify anything below this line ๐๐๐๐๐๐๐๐๐๐ */
function foo(){
console.log('its working');
return 'bar';
}
foo();
module.exports = {
foo,
is31Flavors,
addFlavor,
removeLastFlavor,
getFlavorByIndex,
removeFlavorByName,
copy,
filterByWord,
getAverageWordLength,
getRandomFlavors
}