From 361d5d289e753d1513846fa3d8873bf77969b42a Mon Sep 17 00:00:00 2001 From: sachinsh01 <89263668+sachinsh01@users.noreply.github.com> Date: Mon, 28 Mar 2022 02:30:47 +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: Thu, 7 Apr 2022 23:50:15 +0530 Subject: [PATCH 2/2] ProGrad ID : 8731 --- 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; } +