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

FT_RMT_181124_Lena Cortes #438

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
70 changes: 60 additions & 10 deletions src/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,84 @@
// Iteration 1 | Find the Maximum
function maxOfTwoNumbers() {}



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

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

function findLongestWord() {}
function findLongestWord(arr) {

if (arr.length === 0){
return null;
}

let longestWord = arr[0];
for (let i = 1; i < arr.length; i +=1){
const currentWord = arr[i];
if (currentWord.length > longestWord.length){
longestWord = currentWord;
}
}
return longestWord;
}

findLongestWord(words);




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

function sumNumbers() {}

function sumNumbers(arr) {
let added = 0;
for (let i = 0; i < arr.length; i += 1){
const currentNum = arr[i];
added += arr[i];
}
return added;
}

sumNumbers(numbers);


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

function averageNumbers() {}

function averageNumbers(arr) {
if (arr.length === 0){
return 0;
}
const summedNum = sumNumbers(arr);
const average = summedNum / arr.length;
return average
}

averageNumbers(numbers2);


// Iteration 5 | Find Elements
/* Return true if the word exists in the array; otherwise, return false.*/


const words2 = ["machine", "subset", "trouble", "starting", "matter", "eating", "truth", "disobedience"];

function doesWordExist() {}
function doesWordExist(wordArr, wordToSearch) {
if (wordArr.length === 0){
return null;
}

for (let i= 0; i < wordArr.length; i +=1){
const currentWord = wordArr[i];
if (currentWord === wordToSearch){
return true;
}
}
return false;
}

doesWordExist(words2,"bazooka");