From 1f19e185832849756988cf4673019faa5b64fd81 Mon Sep 17 00:00:00 2001 From: Muhammad Irshad <85778819+Irshadmdk19@users.noreply.github.com> Date: Tue, 10 Sep 2024 21:50:48 +0530 Subject: [PATCH 1/2] Completed 4 iterations --- src/functions-and-arrays.js | 43 +++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec..16c0bb4 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,19 +1,46 @@ // Iteration #1: Find the maximum -function maxOfTwoNumbers() {} +function maxOfTwoNumbers(num1,num2) { + if(num1>num2){ + return num1; + } + else{ + return num2; + } + +} +let result=maxOfTwoNumbers(2,4) +console.log("The maximum number is:"+result); // Iteration #2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; -function findLongestWord() {} +function findLongestWord() { + let longestWord='' + for(let i=0;ilongestWord.length){ + longestWord=words[i] + } + } + return longestWord; +} + +console.log(findLongestWord(words)) // Iteration #3: Calculate the sum const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; -function sumNumbers() {} +function sumNumbers() { + let sum=0; + for(let i=0;i Date: Wed, 11 Sep 2024 20:44:05 +0530 Subject: [PATCH 2/2] solved lab --- src/functions-and-arrays.js | 45 +++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 16c0bb4..c2d478f 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -67,7 +67,15 @@ console.log(averageNumbers(numbers)) // Level 2: Array of strings const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace']; -function averageWordLength() { } +function averageWordLength() { + let sum = 0; + for(let i=0;i