Skip to content
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
98 changes: 82 additions & 16 deletions src/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,100 @@
// Iteration 1 | Find the Maximum
function maxOfTwoNumbers() {}



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

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

function findLongestWord() {}
const words = [
"mystery",
"brother",
"aviator",
"crocodile",
"pearl",
"orchard",
"crackpot",
];

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

let longestWord = words[0];

for (i = 0; i < words.length; i++) {
if (longestWord.length < words[i].length) {
longestWord = words[i];
}
}
return longestWord;
}

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

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

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

// Iteration 3 | Sum Numbers
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
function averageNumbers(arr) {
sum = sumNumbers(arr);
if (!sum) {
return 0;
}
return sum / arr.length;
}

function sumNumbers() {}
// Iteration 5 | Find Elements
const words2 = [
"machine",
"subset",
"trouble",
"starting",
"matter",
"eating",
"truth",
"disobedience",
];

function doesWordExist(arr, word) {
// if (!arr.length) {
// return null;
// }

// for (i = 0; i < arr.length; i++) {
// if (arr[i] === word) {
// console.log(word + " " + arr[i]);
// return true;
// }
// }
// return false;


// Iteration 4 | Numbers Average
const numbers2 = [2, 6, 9, 10, 7, 4, 1, 9];
// let found = false;
// arr.forEach(element => {
// if (element === word) {
// console.log(word + " found");
// found = true;
// }
// });
// return found;

function averageNumbers() {}


}


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

function doesWordExist() {}