Skip to content

Review PR #2379

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 3 commits into from
May 27, 2021
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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ Jest is an automated test-runner for JavaScript.

Before start coding, we will explain the project structure we have provided you.

We will be working with the `src/functions-and-arrays.js` file. To run your tests, open your terminal at the root directory of the lab, run `npm install` to install your dependencies and `npm run test:watch` to generate the `lab-solution.html` file. In case you want to check the tests, they are in the `tests/functions-and-arrays.spec.js` file.
We will be working with the `src/functions-and-arrays.js` file. To run your tests, open your terminal at the root directory of the lab, run `npm install` to install your dependencies and `npm run test:watch` to run the tests and generate the `lab-solution.html` file. In case you want to check the tests, they are in the `tests/functions-and-arrays.spec.js` file.

Open the `lab-solution.html` file using the live server VSCode extension.
Open the `lab-solution.html` file using the [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) VSCode extension.

<br>

Expand All @@ -78,13 +78,13 @@ Note that **you don't need to execute the functions yourself**, the tests are re

### Iteration #1: Find the maximum

Define a function `maxOfTwoNumbers` that takes two numbers as arguments and returns the largest.
Implement the function `maxOfTwoNumbers` that takes two numbers as arguments and returns the largest.

<br>

### Iteration #2: Find the longest word

Declare a function named `findLongestWord` that takes as an argument an array of words and returns the longest one. If there are 2 with the same length, it should return the first occurrence.
Implement the function `findLongestWord` that takes as an argument an array of words and returns the longest one. If there are 2 with the same length, it should return the first occurrence.

You can use the following array to test your solution:

Expand All @@ -98,7 +98,7 @@ const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard',

Calculating a sum can be as simple as iterating over an array and adding each of the elements together.

Declare a function named `sumNumbers` that takes an array of numbers as an argument, and returns the sum of all of the numbers in the array. Later in the course we will learn how to do this by using the `reduce` array method, which will make your work significantly easier. For now, let's practice _"declarative"_ way adding values, using loops.
Implement the function named `sumNumbers` that takes an array of numbers as an argument, and returns the sum of all of the numbers in the array. Later in the course we will learn how to do this by using the `reduce` array method, which will make your work significantly easier. For now, let's practice _"declarative"_ way adding values, using loops.

You can use the following array to test your solution:

Expand All @@ -116,7 +116,7 @@ In the iteration 3, you created a function that returns the sum of an array of n

Here we are applying a concept we call **polymorphism**, that is, dealing with a functions' input independently of the types they are passed as.

Let's create a new function `sum()` that calculates the sum for array filled with (_almost_) any type of data. Note that strings should have their length added to the total, and boolean values should be coerced into their corresponding numeric values. Check the tests for more details.
Let's implement the function `sum()` that calculates the sum for array filled with (_almost_) any type of data. Note that strings should have their length added to the total, and boolean values should be coerced into their corresponding numeric values. Check the tests for more details.

You can use the following array to test your solution:

Expand All @@ -141,7 +141,7 @@ Calculating an average is an extremely common task. Let's practice it a bit.

#### Level 1: Array of numbers

Declare a function named `averageNumbers` that expects an array of numbers and returns the average of the numbers:
Implement the function `averageNumbers` that expects an array of numbers and returns the average of the numbers:

You can use the following array to test your solution:

Expand All @@ -153,7 +153,7 @@ const numbers = [2, 6, 9, 10, 7, 4, 1, 9];

#### Level 2: Array of strings

Declare a function named `averageWordLength` that receives as a single argument an array of words and returns the average length of the words:
Implement the function named `averageWordLength` that receives as a single argument an array of words and returns the average length of the words:

You can use the following array to test your solution:

Expand Down
29 changes: 25 additions & 4 deletions src/functions-and-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,38 @@
function maxOfTwoNumbers() {}



// Iteration #2: Find longest word
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];

function findLongestWord() {}

const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];

// Iteration #3: Calculate the sum

// Iteration #3: Calculate the sum
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];

function sumNumbers() {}



// Iteration #3.1 Bonus:
function sum() {}



// Iteration #4: Calculate the average
// Level 1: Array of numbers
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];

function averageNumbers() {}


// Level 2: Array of strings
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];



// Iteration #5: Unique arrays
const wordsUnique = [
'crab',
Expand All @@ -40,11 +51,15 @@ const wordsUnique = [

function uniquifyArray() {}



// Iteration #6: Find elements
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];

function doesWordExist() {}



// Iteration #7: Count repetition
const wordsCount = [
'machine',
Expand All @@ -62,8 +77,9 @@ const wordsCount = [

function howManyTimes() {}

// Iteration #8: Bonus


// Iteration #8: Bonus
const matrix = [
[8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8],
[49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0],
Expand All @@ -89,12 +105,17 @@ const matrix = [

function greatestProduct() {}

// The following is required to make unit tests work. Please ignore it.



// The following is required to make unit tests work.
/* Environment setup. Do not modify the below code. */
if (typeof module !== 'undefined') {
module.exports = {
maxOfTwoNumbers,
findLongestWord,
sumNumbers,
sum,
averageNumbers,
uniquifyArray,
doesWordExist,
Expand Down
Loading