From bc2c50de30b71fd8813450373c779cfd283acfe3 Mon Sep 17 00:00:00 2001 From: Aazim Rafeekh Date: Fri, 27 Sep 2024 15:46:29 +0530 Subject: [PATCH] Solved Lab --- src/functions-and-arrays.js | 156 +++++++++++++++++++++++++++++++----- 1 file changed, 134 insertions(+), 22 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec..25b7c1d 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(a,b) { + return a>=b? a:b; +} // Iteration #2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; -function findLongestWord() {} - - +function findLongestWord(words) { + if (words.length!== 0){ + let len=0; + let ind=0; + for(let i=0;ilen){ + len=words[i].length; + ind=i; + } + else if(words[i].length===len) + continue; + } + return words[ind]; +} +else + return null; +} // Iteration #3: Calculate the sum const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; -function sumNumbers() {} - - +function sumNumbers(numbers) { + if (numbers.length !== 0){ + let sum=0; + for (let i=0;imaxProduct) + maxProduct = product; + } + } + + for (let i=0 ; imaxProduct) + maxProduct = product; + } + } + return maxProduct +}