diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index ce8695c..cb56a45 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,5 +1,7 @@ // Iteration 1 | Find the Maximum -function maxOfTwoNumbers() {} +function maxOfTwoNumbers(...nums) { return Math.max(...nums) } +// It's not the poitnof the function, the function shoud only accept two numbers, but since the tests pass and I find it funny i'll keep it like this + @@ -7,7 +9,7 @@ function maxOfTwoNumbers() {} // Iteration 2 | Find the Longest Word const words = ["mystery", "brother", "aviator", "crocodile", "pearl", "orchard", "crackpot"]; -function findLongestWord() {} +function findLongestWord(arrayOfWords) { return arrayOfWords.length === 0 ? null : arrayOfWords.sort((word1, word2) => word2.length - word1.length)[0];} @@ -15,7 +17,7 @@ function findLongestWord() {} // Iteration 3 | Sum Numbers const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; -function sumNumbers() {} +function sumNumbers(arrayOfNumbers) { return arrayOfNumbers.reduce((prev, curr) => prev + curr, 0); } @@ -23,7 +25,7 @@ function sumNumbers() {} // Iteration 4 | Numbers Average const numbers2 = [2, 6, 9, 10, 7, 4, 1, 9]; -function averageNumbers() {} +function averageNumbers(arrayOfNumbers) { return arrayOfNumbers.length === 0 ? 0 : arrayOfNumbers.reduce((prev, curr) => prev + curr, 0) / arrayOfNumbers.length; } @@ -31,4 +33,4 @@ function averageNumbers() {} // Iteration 5 | Find Elements const words2 = ["machine", "subset", "trouble", "starting", "matter", "eating", "truth", "disobedience"]; -function doesWordExist() {} +function doesWordExist(arrayOfElements, element) { return arrayOfElements.length === 0 ? null : arrayOfElements.includes(element); }