Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ const words = [
'communion',
'simple',
'bring'
];
]
```

<br>
Expand Down
52 changes: 46 additions & 6 deletions src/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
// Iteration #1: Find the maximum
function maxOfTwoNumbers() {}
function maxOfTwoNumbers(num1, num2) {

if(num1 > num2){

return num1;
} else {
return num2;
}
}
const results = maxOfTwoNumbers (10,11);
comsole.log(results);




// 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;
}

let longestWord = words[0];

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

const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];
const longest = findLongestWord(words);
console.log(`The longest word is: ${longest}`);



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

function sumNumbers() {}

function sumNumbers(numbers) {
let sum = 0;

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

return sum;
}
// Iteration #3.1 Bonus:
function sum() {}

Expand Down Expand Up @@ -59,7 +90,16 @@ function uniquifyArray() {}
// Iteration #6: Find elements
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];

function doesWordExist() {}
function doesWordExist(words, targetWord) {
for (const word of words) {
if (word === targetWord) {
return true; // Word found in the array
}
}
return false; // Word not found in the array
}





Expand Down