Skip to content

Commit b0e2074

Browse files
committed
added more array problems
1 parent 8c3a6da commit b0e2074

File tree

5 files changed

+265
-90
lines changed

5 files changed

+265
-90
lines changed

public/dist/js/bundle.min.js

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

public/dist/js/bundle.min.js.map

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

src/problems/arrays.js

Lines changed: 254 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = [
2929
],
3030
},
3131
{
32-
name: 'Access Array item by index (first)',
32+
name: 'Access Array by index (first)',
3333
time: 10,
3434
prompt: 'Return the first value of the Array',
3535
given: `const fruits = ['apple', 'banana'];\r`,
@@ -51,7 +51,7 @@ module.exports = [
5151
],
5252
},
5353
{
54-
name: 'Access Array item by index (last)',
54+
name: 'Access Array by index (last)',
5555
time: 10,
5656
prompt: 'Return the last value of the Array',
5757
given: `const fruits = ['apple', 'banana', 'orange'];\r`,
@@ -73,7 +73,7 @@ module.exports = [
7373
],
7474
},
7575
{
76-
name: 'Access Array item by index (second)',
76+
name: 'Access Array by index (second)',
7777
time: 10,
7878
prompt: 'Return the second value of the Array',
7979
given: `const fruits = ['apple', 'banana'];\r`,
@@ -95,8 +95,8 @@ module.exports = [
9595
],
9696
},
9797
{
98-
name: 'Loop over array',
99-
time: 30,
98+
name: 'Array.forEach()',
99+
time: 20,
100100
prompt: "Loop over the array, add an 'x' to the end of each name, push each fruit into a new array, then return the new array.",
101101
given: `const fruits = ['apple', 'banana'];\r`,
102102
answer: `const fruits = ['apple', 'banana'];
@@ -127,8 +127,8 @@ module.exports = [
127127
],
128128
},
129129
{
130-
name: 'Add to the end of an Array',
131-
time: 20,
130+
name: 'Array.push()',
131+
time: 10,
132132
prompt: `Add 'orange' to the end of the 'fruits' array and return 'fruits'.`,
133133
given: `const fruits = ['apple', 'banana'];\r`,
134134
answer: `const fruits = ['apple', 'banana'];
@@ -159,8 +159,8 @@ module.exports = [
159159
],
160160
},
161161
{
162-
name: 'Remove from the end of an Array',
163-
time: 20,
162+
name: 'Array.pop()',
163+
time: 10,
164164
prompt: `Remove 'orange' from the end of the 'fruits' array and return 'fruits'.`,
165165
given: `const fruits = ['apple', 'banana', 'orange'];\r`,
166166
answer: `const fruits = ['apple', 'banana', 'orange'];
@@ -188,8 +188,8 @@ module.exports = [
188188
],
189189
},
190190
{
191-
name: 'Remove from the front of an Array',
192-
time: 20,
191+
name: 'Array.shift()',
192+
time: 10,
193193
prompt: `Remove 'apple' from the front of the 'fruits' array and return 'fruits'.`,
194194
given: `const fruits = ['apple', 'banana', 'orange'];\r`,
195195
answer: `const fruits = ['apple', 'banana', 'orange'];
@@ -217,8 +217,8 @@ module.exports = [
217217
],
218218
},
219219
{
220-
name: 'Add to the front of an Array',
221-
time: 20,
220+
name: 'Array.unshift()',
221+
time: 10,
222222
prompt: `Add 'strawberry' to the front of the 'fruits' array and return 'fruits'.`,
223223
given: `const fruits = ['apple', 'banana', 'orange'];\r`,
224224
answer: `const fruits = ['apple', 'banana', 'orange'];
@@ -253,8 +253,8 @@ module.exports = [
253253
],
254254
},
255255
{
256-
name: 'Find the index of an item in the Array',
257-
time: 20,
256+
name: 'Array.indexOf()',
257+
time: 10,
258258
prompt: `Return the index of 'banana' in the Array.`,
259259
given: `const fruits = ['strawberry', 'banana', 'mango'];\r`,
260260
answer: `const fruits = ['strawberry', 'banana', 'mango'];
@@ -275,4 +275,243 @@ module.exports = [
275275
},
276276
],
277277
},
278+
{
279+
name: 'Array.concat()',
280+
time: 10,
281+
prompt: `Merge the two arrays using Array's 'concat()' method. Return the resulting array.`,
282+
given: `const fruits = ['strawberry', 'banana'];\rconst otherFruits = ['pear','peach'];\r`,
283+
answer: `const fruits = ['strawberry', 'banana'];
284+
const otherFruits = ['pear','peach'];
285+
const allTheFruits = fruits.concat(otherFruits);
286+
return allTheFruits;\r`,
287+
tests: [
288+
{
289+
name: 'Correct output',
290+
test: function(output) {
291+
return (
292+
assert.deepEqual(output, [
293+
'strawberry',
294+
'banana',
295+
'pear',
296+
'peach',
297+
]) === undefined
298+
);
299+
},
300+
},
301+
{
302+
name: 'Returns an Array',
303+
test: function(output) {
304+
return assert.isArray(output) === undefined;
305+
},
306+
},
307+
{
308+
name: 'Array has 4 items',
309+
test: function(output) {
310+
return assert.lengthOf(output, 4) === undefined;
311+
},
312+
},
313+
],
314+
},
315+
{
316+
name: 'Array.join()',
317+
time: 10,
318+
prompt: `Mix the two flavors with a '-' using Array's 'join' method. Return the resulting hybrid flavor.`,
319+
given: `const fruits = ['strawberry', 'banana'];\r`,
320+
answer: `const fruits = ['strawberry', 'banana'];
321+
const hybrid = fruits.join('-');
322+
return hybrid;\r`,
323+
tests: [
324+
{
325+
name: 'Correct output',
326+
test: function(output) {
327+
return assert.deepEqual(output, 'strawberry-banana') === undefined;
328+
},
329+
},
330+
{
331+
name: 'Returns a String',
332+
test: function(output) {
333+
return assert.isString(output) === undefined;
334+
},
335+
},
336+
],
337+
},
338+
{
339+
name: 'Array.slice()',
340+
time: 20,
341+
prompt: `Return just the citrus fruits from the 'fruits' array using 'Array.slice()'`,
342+
given: `const fruits = ['strawberry', 'orange', 'lemon', 'banana'];\r`,
343+
answer: `const fruits = ['strawberry', 'orange', 'lemon', 'banana'];
344+
const citrus = fruits.slice(1, 3);
345+
return citrus;`,
346+
tests: [
347+
{
348+
name: 'Correct output',
349+
test: function(output) {
350+
return assert.deepEqual(output, ['orange', 'lemon']) === undefined;
351+
},
352+
},
353+
{
354+
name: 'Returns an Array',
355+
test: function(output) {
356+
return assert.isArray(output) === undefined;
357+
},
358+
},
359+
{
360+
name: 'Array has 2 items',
361+
test: function(output) {
362+
return assert.lengthOf(output, 2) === undefined;
363+
},
364+
},
365+
],
366+
},
367+
{
368+
name: 'Array.reverse()',
369+
time: 10,
370+
prompt: `Reverse the order of the 'fruit' array using 'Array.reverse()'`,
371+
given: `const fruits = ['strawberry', 'orange', 'lemon', 'banana'];\r`,
372+
answer: `const fruits = ['strawberry', 'orange', 'lemon', 'banana'];
373+
const stiurf = fruits.reverse();
374+
return stiurf;`,
375+
tests: [
376+
{
377+
name: 'Correct output',
378+
test: function(output) {
379+
return (
380+
assert.deepEqual(output, [
381+
'banana',
382+
'lemon',
383+
'orange',
384+
'strawberry',
385+
]) === undefined
386+
);
387+
},
388+
},
389+
{
390+
name: 'Returns an Array',
391+
test: function(output) {
392+
return assert.isArray(output) === undefined;
393+
},
394+
},
395+
{
396+
name: 'Array has 4 items',
397+
test: function(output) {
398+
return assert.lengthOf(output, 4) === undefined;
399+
},
400+
},
401+
{
402+
name: `First item is 'banana'`,
403+
test: function(output) {
404+
return assert.deepEqual(output[0], 'banana') === undefined;
405+
},
406+
},
407+
],
408+
},
409+
{
410+
name: 'Array.sort()',
411+
time: 10,
412+
prompt: `Sort the order of the 'fruit' array using 'Array.sort()'`,
413+
given: `const fruits = ['strawberry', 'orange', 'lemon', 'banana'];\r`,
414+
answer: `const fruits = ['strawberry', 'orange', 'lemon', 'banana'];
415+
const orderlyFruit = fruits.sort();
416+
return orderlyFruit;`,
417+
tests: [
418+
{
419+
name: 'Correct output',
420+
test: function(output) {
421+
return (
422+
assert.deepEqual(output, [
423+
'banana',
424+
'lemon',
425+
'orange',
426+
'strawberry',
427+
]) === undefined
428+
);
429+
},
430+
},
431+
{
432+
name: 'Returns an Array',
433+
test: function(output) {
434+
return assert.isArray(output) === undefined;
435+
},
436+
},
437+
{
438+
name: 'Array has 4 items',
439+
test: function(output) {
440+
return assert.lengthOf(output, 4) === undefined;
441+
},
442+
},
443+
{
444+
name: `First item is 'banana'`,
445+
test: function(output) {
446+
return assert.deepEqual(output[0], 'banana') === undefined;
447+
},
448+
},
449+
],
450+
},
451+
{
452+
name: 'Array.lastIndexOf()',
453+
time: 10,
454+
prompt: `Return the index of the last 'peach' instance in the 'fruit' array using 'Array.lastIndexOf()'`,
455+
given: `const fruits = ['peach', 'orange', 'lemon', 'peach'];\r`,
456+
answer: `const fruits = ['peach', 'orange', 'lemon', 'peach'];
457+
const wheresTheLastPeach = fruits.lastIndexOf('peach');
458+
return wheresTheLastPeach;`,
459+
tests: [
460+
{
461+
name: 'Correct output',
462+
test: function(output) {
463+
return assert.deepEqual(output, 3) === undefined;
464+
},
465+
},
466+
{
467+
name: 'Returns a Number',
468+
test: function(output) {
469+
return assert.isNumber(output) === undefined;
470+
},
471+
},
472+
],
473+
},
474+
// forEach? fix one above that tried, but can't verify forEach was used
475+
// .map
476+
// filter
477+
{
478+
name: 'Array.filter()',
479+
time: 10,
480+
prompt: `return an array of the numbers greater than 5 in 'fruits' using 'Array.filter()'`,
481+
given: `const numbers = [1, 1, 2, 3, 5, 8, 13, 21];\r`,
482+
answer: `const numbers = [1, 1, 2, 3, 5, 8, 13, 21];
483+
const overFive = numbers.filter(num => num > 5);
484+
return overFive;`,
485+
tests: [
486+
{
487+
name: 'Correct output',
488+
test: function(output) {
489+
return assert.deepEqual(output, [8, 13, 21]) === undefined;
490+
},
491+
},
492+
{
493+
name: 'Returns an Array',
494+
test: function(output) {
495+
return assert.isArray(output) === undefined;
496+
},
497+
},
498+
{
499+
name: 'Array has 3 items',
500+
test: function(output) {
501+
return assert.lengthOf(output, 3) === undefined;
502+
},
503+
},
504+
{
505+
name: `First item is 8`,
506+
test: function(output) {
507+
return assert.deepEqual(output[0], 8) === undefined;
508+
},
509+
},
510+
],
511+
},
512+
// every
513+
// some
514+
// reduce
515+
// reduceRight
516+
// Array.from and other ways to turn array-like into array
278517
];

0 commit comments

Comments
 (0)