Skip to content

Completed the first 3 iterations #3705

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 4 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
completed the first 3 iterations
  • Loading branch information
dbravojuanico committed Mar 30, 2023
commit 2c943bfff6b73fbb566d5b1ce2a8aa3f1d6b2af8
38 changes: 29 additions & 9 deletions src/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
// Iteration #1: Find the maximum
function maxOfTwoNumbers() {}


function maxOfTwoNumbers(firstNumber, secondNumber) {
if (firstNumber >= secondNumber) {
return firstNumber
} else {
return secondNumber
}
}

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

function findLongestWord() {}


function findLongestWord(randomArray) {
if (randomArray.length <= 0) {
return null
} else if (randomArray.length === 1) {
return randomArray[0]
} else {
let longestWord = ""
for (j = 0; j < randomArray.length; j++) {
if (longestWord.length < randomArray[j].length){
longestWord = randomArray[j]
}
}
return longestWord
}
}

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

function sumNumbers() {}


function sumNumbers(refArray) {
let result = 0
for (let i = 0; i < refArray.length; i++ ){
result = result + refArray[i]
}
return result
}

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