From 778904b358c50f0d2f6ad7561d3736cb99006283 Mon Sep 17 00:00:00 2001 From: rbc33 Date: Tue, 2 Sep 2025 21:47:56 +0200 Subject: [PATCH 1/2] done --- src/functions-and-arrays.js | 74 +++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index ce8695c..e12c1c2 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,34 +1,62 @@ // Iteration 1 | Find the Maximum -function maxOfTwoNumbers() {} - - - +function maxOfTwoNumbers(num1, num2) { + if (num1 == num2) return num1, num2 + return Math.max(num1, num2) +} // 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.map((word) => { + if (word.length > longestWord.length) { + longestWord = word + } + }) + return longestWord +} // Iteration 3 | Sum Numbers -const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; - -function sumNumbers() {} - - +const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10] +function sumNumbers(numbers) { + return numbers.reduce((acc, curr) => acc + curr, 0) +} // Iteration 4 | Numbers Average -const numbers2 = [2, 6, 9, 10, 7, 4, 1, 9]; - -function averageNumbers() {} - - +const numbers2 = [2, 6, 9, 10, 7, 4, 1, 9] +function averageNumbers(numbers2) { + if (numbers2.length == 0) return 0 + return sumNumbers(numbers2) / numbers2.length +} // Iteration 5 | Find Elements -const words2 = ["machine", "subset", "trouble", "starting", "matter", "eating", "truth", "disobedience"]; - -function doesWordExist() {} +const words2 = [ + 'machine', + 'subset', + 'trouble', + 'starting', + 'matter', + 'eating', + 'truth', + 'disobedience', +] + +function doesWordExist(words2, word) { + if (words2.length == 0) return null + for (let i = 0; i < words2.length; i++) { + if (words2[i] === word) return true + } + return false +} From 258b252946c109f1bb7a4f20127378df98a939ab Mon Sep 17 00:00:00 2001 From: rbc33 Date: Thu, 11 Sep 2025 20:51:04 +0200 Subject: [PATCH 2/2] done --- src/functions-and-arrays.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index e12c1c2..2113f02 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -53,10 +53,12 @@ const words2 = [ 'disobedience', ] -function doesWordExist(words2, word) { - if (words2.length == 0) return null - for (let i = 0; i < words2.length; i++) { - if (words2[i] === word) return true - } - return false +function doesWordExist(words, word) { + if (words.length == 0) return null + // for (let i = 0; i < words.length; i++) { + // if (words[i] === word) return true + // } + // words.map(w => if (w === word) return true) + // return false + return words.some((w) => w === word) }