Skip to content

added more array problems #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions public/dist/js/bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/dist/js/bundle.min.js.map

Large diffs are not rendered by default.

269 changes: 254 additions & 15 deletions src/problems/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = [
],
},
{
name: 'Access Array item by index (first)',
name: 'Access Array by index (first)',
time: 10,
prompt: 'Return the first value of the Array',
given: `const fruits = ['apple', 'banana'];\r`,
Expand All @@ -51,7 +51,7 @@ module.exports = [
],
},
{
name: 'Access Array item by index (last)',
name: 'Access Array by index (last)',
time: 10,
prompt: 'Return the last value of the Array',
given: `const fruits = ['apple', 'banana', 'orange'];\r`,
Expand All @@ -73,7 +73,7 @@ module.exports = [
],
},
{
name: 'Access Array item by index (second)',
name: 'Access Array by index (second)',
time: 10,
prompt: 'Return the second value of the Array',
given: `const fruits = ['apple', 'banana'];\r`,
Expand All @@ -95,8 +95,8 @@ module.exports = [
],
},
{
name: 'Loop over array',
time: 30,
name: 'Array.forEach()',
time: 20,
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.",
given: `const fruits = ['apple', 'banana'];\r`,
answer: `const fruits = ['apple', 'banana'];
Expand Down Expand Up @@ -127,8 +127,8 @@ module.exports = [
],
},
{
name: 'Add to the end of an Array',
time: 20,
name: 'Array.push()',
time: 10,
prompt: `Add 'orange' to the end of the 'fruits' array and return 'fruits'.`,
given: `const fruits = ['apple', 'banana'];\r`,
answer: `const fruits = ['apple', 'banana'];
Expand Down Expand Up @@ -159,8 +159,8 @@ module.exports = [
],
},
{
name: 'Remove from the end of an Array',
time: 20,
name: 'Array.pop()',
time: 10,
prompt: `Remove 'orange' from the end of the 'fruits' array and return 'fruits'.`,
given: `const fruits = ['apple', 'banana', 'orange'];\r`,
answer: `const fruits = ['apple', 'banana', 'orange'];
Expand Down Expand Up @@ -188,8 +188,8 @@ module.exports = [
],
},
{
name: 'Remove from the front of an Array',
time: 20,
name: 'Array.shift()',
time: 10,
prompt: `Remove 'apple' from the front of the 'fruits' array and return 'fruits'.`,
given: `const fruits = ['apple', 'banana', 'orange'];\r`,
answer: `const fruits = ['apple', 'banana', 'orange'];
Expand Down Expand Up @@ -217,8 +217,8 @@ module.exports = [
],
},
{
name: 'Add to the front of an Array',
time: 20,
name: 'Array.unshift()',
time: 10,
prompt: `Add 'strawberry' to the front of the 'fruits' array and return 'fruits'.`,
given: `const fruits = ['apple', 'banana', 'orange'];\r`,
answer: `const fruits = ['apple', 'banana', 'orange'];
Expand Down Expand Up @@ -253,8 +253,8 @@ module.exports = [
],
},
{
name: 'Find the index of an item in the Array',
time: 20,
name: 'Array.indexOf()',
time: 10,
prompt: `Return the index of 'banana' in the Array.`,
given: `const fruits = ['strawberry', 'banana', 'mango'];\r`,
answer: `const fruits = ['strawberry', 'banana', 'mango'];
Expand All @@ -275,4 +275,243 @@ module.exports = [
},
],
},
{
name: 'Array.concat()',
time: 10,
prompt: `Merge the two arrays using Array's 'concat()' method. Return the resulting array.`,
given: `const fruits = ['strawberry', 'banana'];\rconst otherFruits = ['pear','peach'];\r`,
answer: `const fruits = ['strawberry', 'banana'];
const otherFruits = ['pear','peach'];
const allTheFruits = fruits.concat(otherFruits);
return allTheFruits;\r`,
tests: [
{
name: 'Correct output',
test: function(output) {
return (
assert.deepEqual(output, [
'strawberry',
'banana',
'pear',
'peach',
]) === undefined
);
},
},
{
name: 'Returns an Array',
test: function(output) {
return assert.isArray(output) === undefined;
},
},
{
name: 'Array has 4 items',
test: function(output) {
return assert.lengthOf(output, 4) === undefined;
},
},
],
},
{
name: 'Array.join()',
time: 10,
prompt: `Mix the two flavors with a '-' using Array's 'join' method. Return the resulting hybrid flavor.`,
given: `const fruits = ['strawberry', 'banana'];\r`,
answer: `const fruits = ['strawberry', 'banana'];
const hybrid = fruits.join('-');
return hybrid;\r`,
tests: [
{
name: 'Correct output',
test: function(output) {
return assert.deepEqual(output, 'strawberry-banana') === undefined;
},
},
{
name: 'Returns a String',
test: function(output) {
return assert.isString(output) === undefined;
},
},
],
},
{
name: 'Array.slice()',
time: 20,
prompt: `Return just the citrus fruits from the 'fruits' array using 'Array.slice()'`,
given: `const fruits = ['strawberry', 'orange', 'lemon', 'banana'];\r`,
answer: `const fruits = ['strawberry', 'orange', 'lemon', 'banana'];
const citrus = fruits.slice(1, 3);
return citrus;`,
tests: [
{
name: 'Correct output',
test: function(output) {
return assert.deepEqual(output, ['orange', 'lemon']) === undefined;
},
},
{
name: 'Returns an Array',
test: function(output) {
return assert.isArray(output) === undefined;
},
},
{
name: 'Array has 2 items',
test: function(output) {
return assert.lengthOf(output, 2) === undefined;
},
},
],
},
{
name: 'Array.reverse()',
time: 10,
prompt: `Reverse the order of the 'fruit' array using 'Array.reverse()'`,
given: `const fruits = ['strawberry', 'orange', 'lemon', 'banana'];\r`,
answer: `const fruits = ['strawberry', 'orange', 'lemon', 'banana'];
const stiurf = fruits.reverse();
return stiurf;`,
tests: [
{
name: 'Correct output',
test: function(output) {
return (
assert.deepEqual(output, [
'banana',
'lemon',
'orange',
'strawberry',
]) === undefined
);
},
},
{
name: 'Returns an Array',
test: function(output) {
return assert.isArray(output) === undefined;
},
},
{
name: 'Array has 4 items',
test: function(output) {
return assert.lengthOf(output, 4) === undefined;
},
},
{
name: `First item is 'banana'`,
test: function(output) {
return assert.deepEqual(output[0], 'banana') === undefined;
},
},
],
},
{
name: 'Array.sort()',
time: 10,
prompt: `Sort the order of the 'fruit' array using 'Array.sort()'`,
given: `const fruits = ['strawberry', 'orange', 'lemon', 'banana'];\r`,
answer: `const fruits = ['strawberry', 'orange', 'lemon', 'banana'];
const orderlyFruit = fruits.sort();
return orderlyFruit;`,
tests: [
{
name: 'Correct output',
test: function(output) {
return (
assert.deepEqual(output, [
'banana',
'lemon',
'orange',
'strawberry',
]) === undefined
);
},
},
{
name: 'Returns an Array',
test: function(output) {
return assert.isArray(output) === undefined;
},
},
{
name: 'Array has 4 items',
test: function(output) {
return assert.lengthOf(output, 4) === undefined;
},
},
{
name: `First item is 'banana'`,
test: function(output) {
return assert.deepEqual(output[0], 'banana') === undefined;
},
},
],
},
{
name: 'Array.lastIndexOf()',
time: 10,
prompt: `Return the index of the last 'peach' instance in the 'fruit' array using 'Array.lastIndexOf()'`,
given: `const fruits = ['peach', 'orange', 'lemon', 'peach'];\r`,
answer: `const fruits = ['peach', 'orange', 'lemon', 'peach'];
const wheresTheLastPeach = fruits.lastIndexOf('peach');
return wheresTheLastPeach;`,
tests: [
{
name: 'Correct output',
test: function(output) {
return assert.deepEqual(output, 3) === undefined;
},
},
{
name: 'Returns a Number',
test: function(output) {
return assert.isNumber(output) === undefined;
},
},
],
},
// forEach? fix one above that tried, but can't verify forEach was used
// .map
// filter
{
name: 'Array.filter()',
time: 10,
prompt: `return an array of the numbers greater than 5 in 'fruits' using 'Array.filter()'`,
given: `const numbers = [1, 1, 2, 3, 5, 8, 13, 21];\r`,
answer: `const numbers = [1, 1, 2, 3, 5, 8, 13, 21];
const overFive = numbers.filter(num => num > 5);
return overFive;`,
tests: [
{
name: 'Correct output',
test: function(output) {
return assert.deepEqual(output, [8, 13, 21]) === undefined;
},
},
{
name: 'Returns an Array',
test: function(output) {
return assert.isArray(output) === undefined;
},
},
{
name: 'Array has 3 items',
test: function(output) {
return assert.lengthOf(output, 3) === undefined;
},
},
{
name: `First item is 8`,
test: function(output) {
return assert.deepEqual(output[0], 8) === undefined;
},
},
],
},
// every
// some
// reduce
// reduceRight
// Array.from and other ways to turn array-like into array
];
Loading