diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec41..7a9b4d2f0 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,41 +1,105 @@ // Iteration #1: Find the maximum -function maxOfTwoNumbers() {} - - +function maxOfTwoNumbers(num1, num2) { + if(num1>num2){ + return num1 + } + else if(num2>num1){ + return num2 + } + return num1 +} // Iteration #2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; -function findLongestWord() {} - - +function findLongestWord(name) { + const wordArray = [] + if(name.length===0){return null} + else if(name.length===1){return name[0]} + for(let i=0; i result) { + result = rowProduct; + } + } + } + + for (let k = 0; k < countColumns; k++) { + for (let l = 0; l < countRows - 3; l++) { + let columnProduct = matrix[l][k] * matrix[l + 1][k] * matrix[l + 2][k] * matrix[l + 3][k]; + if (columnProduct > result) { + result = columnProduct; + } + } + } + return result; +} // The following is required to make unit tests work.