Skip to content

primeros ejercicios #3786

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
primeros ejercicios
  • Loading branch information
marybonilla committed May 10, 2023
commit 41a86390ceb49c06fc03c1d0556419b1d45a7d04
55 changes: 49 additions & 6 deletions src/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,56 @@
// Iteration #1: Find the maximum
function maxOfTwoNumbers() {}

function maxOfTwoNumbers(num1, num2) {
if(num1 > num2)
return num1
else if(num1 < num2){
return num2
}else{
return num1
}
}


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

function findLongestWord() {}
function findLongestWord(words) {
if (words.length === 0){
return null}

if (words.length===1){
return word1[0]
}

for (let i = 1; i < words.length; i++) {
if (words[i].length > word2.length) {
word2 = words[i];
}
}

}









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

function sumNumbers() {}

function sumNumbers (numbers) {
if (numbers.length === 0){
return 0}
let sum = 0;
for(let i = 0; i < numbers.length; i++){
sum += numbers[i];
}
return sum;
}

console.log(sumNumbers([1, 2, 3, 4]));

// Iteration #3.1 Bonus:
function sum() {}
Expand All @@ -26,7 +61,15 @@ function sum() {}
// Level 1: Array of numbers
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];

function averageNumbers() {}
function averageNumbers(numbersAvg) {
if (numbersAvg.length === 0){
return null}

}






// Level 2: Array of strings
Expand Down