From e5ab7fb32ad1b7a704f2cfc0b59d7622e9396c58 Mon Sep 17 00:00:00 2001 From: Shreshth Jaiswal <67462416+shreshth02@users.noreply.github.com> Date: Mon, 28 Mar 2022 10:02:14 +0530 Subject: [PATCH 1/2] Update functions-and-arrays.js --- src/functions-and-arrays.js | 115 +++++++++++++++++++++++++++++++++--- 1 file changed, 107 insertions(+), 8 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 18c9498..eaec18c 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,18 +1,81 @@ // Progression #1: Greatest of the two numbers - +function greatestOfTwoNumbers(a,b){ + return a>b?a:b; +} // Progression #2: The lengthy word -const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; - +var words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; +function findScaryWord(words){ + if(words.length===0) + return null; + var j=0; + for(var i=1;i=words[i].length?(words[i]=words[i-1]):j++; + } + return words[words.length-1]; +} // Progression #3: Net Price const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; - +function netPrice(arr){ + if(arr.length===0) + return 0; + return arr.reduce((a,b)=>a+b) +} +function add(arr){ + var total=0; + if(arr.length===0) + return 0; + for(var i=0;ia+b)/arr.length +} // Progression 4.2: Array of strings const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace']; - +function averageWordLength(arr){ + var total=0; +if(arr.length===0) + return null; + for(var i=0;i Date: Fri, 8 Apr 2022 09:35:15 +0530 Subject: [PATCH 2/2] Prograd ID : 8730 --- src/functions-and-arrays.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index eaec18c..6921c46 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -160,3 +160,4 @@ function maximumProduct(matrix){ } return pro; } +