From 6ab69bc6de99de40e23234f618cea213aa5ae018 Mon Sep 17 00:00:00 2001 From: Nil E Date: Sun, 21 Jan 2024 22:54:45 +0100 Subject: [PATCH 1/2] all done except 8.2 --- src/functions-and-arrays.js | 253 ++++++++++++++++++++++++++++++++---- 1 file changed, 231 insertions(+), 22 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec41..ef0c36194 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; + } + } + //vertical + for (let j=0; j biggest) { + biggest = verticalmultiplied; + } + else if (verticalmultiplied <= biggest) { + continue; + } + } + return biggest; + } From ee083f136adccb2ecb6920c40013801a62ca24b8 Mon Sep 17 00:00:00 2001 From: nil-e <154754621+nil-e@users.noreply.github.com> Date: Sun, 21 Jan 2024 22:56:48 +0100 Subject: [PATCH 2/2] Update functions-and-arrays.js removed commented out parts --- src/functions-and-arrays.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index ef0c36194..6d4553e7a 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -270,13 +270,11 @@ const matrix = [ function greatestProduct(myArr) { let biggest = 1; - //horizontal for (let i=0; i