From 6a33064a08bd044885d9f0247bf3b7f2f99da696 Mon Sep 17 00:00:00 2001 From: Prantik-Bhattacharjee Date: Tue, 22 Mar 2022 21:59:14 +0530 Subject: [PATCH] updated - 19BCE10222 --- 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..e618c77 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