diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec41..6d4553e7a 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,24 +1,81 @@ // Iteration #1: Find the maximum -function maxOfTwoNumbers() {} - - +function maxOfTwoNumbers(i,j) { + if (i>j) { + return i; + } + else if (i 0) { + let lengthsArr=[]; + let longest = test[0].length; + let longestword = test[0]; + for (let i=0; i longest) { + longest = test[i].length; + longestword = test[i]; + } + else if (longest >= test[i].length) { + + continue; + } + } + return longestword; + } +} -// Iteration #3: Calculate the sum +// Iteration #3: #3.1 Calculate the sum const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; -function sumNumbers() {} - - +function sumNumbers(numList) { + let sum=0; + for(let i=0; i0) { + let sum=0; + let count=0; + for(let i=0; i 0) { + let sum=0; + let count=0; + for(let i=0; i 0) { + for(let i=0; i 0) { + let uniqueList = []; + for(let i=0; i< wordList.length; i++) { + if (uniqueList.length == 0) { + uniqueList.push(wordList[i]); + } + else if (uniqueList.includes(wordList[i])) { + continue; + } + else if (!uniqueList.includes(wordList[i])) { + uniqueList.push(wordList[i]); + } + } + return uniqueList; + } +} // Iteration #6: Find elements const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience']; -function doesWordExist() {} +function doesWordExist(wordList,searchKeyword) { + if (wordList.length == 0) { + return null; + } + else if (wordList.length > 0) { + return wordList.includes(searchKeyword); + } +} @@ -78,9 +222,27 @@ const wordsCount = [ 'matter' ]; -function howManyTimes() {} - - +function howManyTimes(wordList,searchKeyword) { + if (wordList.length == 0) { + return 0; + } + else if(!wordList.includes(searchKeyword)) { + return 0; + } + else if (wordList.length > 0 || wordList.includes(searchKeyword)) + { + let count = 0; + for(let i = 0;i biggest) { + biggest = horizontalmultiplied; + } + else if (horizontalmultiplied <= biggest) { + continue; + } + } + for (let j=0; j biggest) { + biggest = verticalmultiplied; + } + else if (verticalmultiplied <= biggest) { + continue; + } + } + return biggest; + }