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

PT_RMT_181124 Patricio #442

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
73 changes: 60 additions & 13 deletions src/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,81 @@
// 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(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];
}
}
return longestWord;
}

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

function sumNumbers() {}


function sumNumbers(numbers) {
if (numbers.length === 0) {
return 0;
}

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

}


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

function averageNumbers() {}
function averageNumbers(numbers2) {
if (numbers2.length === 0) {
return 0;
}
let sum1 = 0;
for (let i=0; i < numbers2.length; i++) {
sum1 += numbers2[i];
}
return sum1 / numbers2.length;
}
console.log(averageNumbers(numbers2));




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

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


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

}

console.log(doesWordExist(words2))