From e43d5aa43543b73fdad737c34f4c902e2f258e58 Mon Sep 17 00:00:00 2001 From: kritikamandale Date: Wed, 22 Oct 2025 19:28:02 +0530 Subject: [PATCH 1/4] my first and 2nd iteration is done --- src/functions-and-arrays.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3a7dbec..3b38187 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,12 +1,30 @@ // Iteration #1: Find the maximum -function maxOfTwoNumbers() {} - +function maxOfTwoNumbers(num1,num2) { + if(num1>num2){ + return num1; + } + else{ + return num2; + } +} +const result1= maxOfTwoNumbers(10,2); +console.log(result1); // Iteration #2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; -function findLongestWord() {} +function findLongestWord() { + let longestw =""; + for(let i=0;i longestw.length){ + longestw=words[i]; + } + } + return longestw; +} +const result2 = findLongestWord(); +console.log(result2); From caa9582f17c0a493221e2d6f3bcbdb4cb4c3a8bd Mon Sep 17 00:00:00 2001 From: kritikamandale Date: Wed, 22 Oct 2025 19:39:39 +0530 Subject: [PATCH 2/4] my third iteration is done --- src/functions-and-arrays.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 3b38187..a48d99f 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -30,8 +30,15 @@ console.log(result2); // 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, 22 Oct 2025 20:47:44 +0530 Subject: [PATCH 3/4] my fourth iteration is done --- src/functions-and-arrays.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index a48d99f..a81a9e2 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -43,7 +43,9 @@ console.log(result3); // Iteration #3.1 Bonus: -function sum() {} +function sum() { + +} @@ -51,13 +53,36 @@ function sum() {} // Level 1: Array of numbers const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; -function averageNumbers() {} +function averageNumbers() { + let avg=0; + for(let i=0;i Date: Wed, 22 Oct 2025 21:06:46 +0530 Subject: [PATCH 4/4] my seventsh iteration is also done --- src/functions-and-arrays.js | 42 +++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index a81a9e2..871d181 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -102,15 +102,38 @@ const wordsUnique = [ 'bring' ]; -function uniquifyArray() {} +function uniquifyArray(wordsArray) { + const uniqueWords = []; + for (let i = 0; i < wordsArray.length; i++) { + if (uniqueWords.indexOf(wordsArray[i]) === -1) { + uniqueWords.push(wordsArray[i]); + } + } + return uniqueWords; +} + +const result = uniquifyArray(wordsUnique); +console.log(result); // Iteration #6: Find elements const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience']; -function doesWordExist() {} - +function doesWordExist(wordsArray, wordToSearch) { + if (wordsArray.length === 0) { + return false; + } + + for (let i = 0; i < wordsArray.length; i++) { + if (wordsArray[i] === wordToSearch) { + return true; + } + } + return false; +} +console.log(doesWordExist(words, 'poison')); +console.log(doesWordExist(words, 'fish')); // Iteration #7: Count repetition @@ -128,7 +151,18 @@ const wordsCount = [ 'matter' ]; -function howManyTimes() {} +function howManyTimes(wordsArray, wordToSearch) { + let count = 0; + for (let i = 0; i < wordsArray.length; i++) { + if (wordsArray[i] === wordToSearch) { + count++; + } + } + return count; +} +console.log(howManyTimes(wordsCount, 'matter')); +console.log(howManyTimes(wordsCount, 'machine')); +console.log(howManyTimes(wordsCount, 'trouble'));