Skip to content

[RMTWD-022023] - Hugo #3660

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

Closed
wants to merge 2 commits into from
Closed
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
76 changes: 68 additions & 8 deletions src/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
// Iteration #1: Find the maximum
function maxOfTwoNumbers() {}
function maxOfTwoNumbers(num1, num2) {
if (num1 > num2) {
return num1;
}else if (num1 < num2) {
return num2;
}else return num1,num2;
}



// Iteration #2: Find longest word
const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot'];

function findLongestWord() {}

function findLongestWord(longest) {
if (longest.length === 0) {
return null;
}
else {
let word = "";
for (let i = 0; i < longest.length; i++) {
if (word.length < longest[i].length) {
word = longest[i];
}
}
return word;
}
}


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

function sumNumbers() {}

function sumNumbers(nums) {
let sum = 0;

if (nums.length === 0) {
return 0;
}
else {
for (let i = 0; i < nums.length; i++)
sum += nums[i];
}
console.log(sum);
return sum;
}


// Iteration #3.1 Bonus:
Expand All @@ -26,13 +55,36 @@ function sum() {}
// Level 1: Array of numbers
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9];

function averageNumbers() {}
function averageNumbers(nums) {
let aveNum = 0;

if (nums.length === 0) {
return null;
}
else {
for (let i = 0; i < nums.length; i++) {
aveNum += nums[i];
}
return aveNum/nums.length;
}
}


// Level 2: Array of strings
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];

function averageWordLength() { }
function averageWordLength(words) {
let aveWords = 0;
if (words.length === 0) {
return null;
}
else {
for (let i = 0; i < words.length; i++) {
aveWords += words[i].length;
}
return aveWords/words.length;
}
}

// Bonus - Iteration #4.1
function avg() {}
Expand All @@ -59,7 +111,15 @@ function uniquifyArray() {}
// Iteration #6: Find elements
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];

function doesWordExist() {}
function doesWordExist(array, target) {
if (array.length === 0) {
return null;
}
else {
return array.includes(target);

}
}



Expand Down