Skip to content
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

Jasmine is a very nice person <3 #424

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
61 changes: 56 additions & 5 deletions src/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,85 @@
// Iteration 1 | Find the Maximum
function maxOfTwoNumbers() {}
function maxOfTwoNumbers(arg1, arg2) {
switch (true) {
case arg1 === arg2:
return arg1;
case arg1 > arg2:
return arg1
default:
return arg2;
}

}




// Iteration 2 | Find the Longest Word
const words = ["mystery", "brother", "aviator", "crocodile", "pearl", "orchard", "crackpot"];

function findLongestWord() {}
function findLongestWord(arrayOfStrings) {
let longestWord = '';

if (arrayOfStrings.length === 0) {
return null;

} else if(arrayOfStrings.length === 1) {
return arrayOfStrings[0];

} else if (arrayOfStrings.length > 1) {
longestWord = arrayOfStrings.at(0);

arrayOfStrings.forEach((word) => {
if (word.length > longestWord.length) {
longestWord = word;
}
})
return longestWord;
}

}




// Iteration 3 | Sum Numbers
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];

function sumNumbers() {}
function sumNumbers(arrayOfNumbers) {
let sumOfArray = 0;

arrayOfNumbers.forEach((number) => {
sumOfArray += number;
})
return sumOfArray;
}




// Iteration 4 | Numbers Average
const numbers2 = [2, 6, 9, 10, 7, 4, 1, 9];

function averageNumbers() {}
function averageNumbers(arrayOfNumbers) {
let theSum = sumNumbers(arrayOfNumbers);

if(arrayOfNumbers.length === 0) {
return 0;
}

return theSum / arrayOfNumbers.length;
}




// Iteration 5 | Find Elements
const words2 = ["machine", "subset", "trouble", "starting", "matter", "eating", "truth", "disobedience"];

function doesWordExist() {}
function doesWordExist(arrayOfWords, word) {
if (arrayOfWords.length === 0) {
return null;
}

return arrayOfWords.includes(word);
}