From e27328d5c4fbc5a1764b377dab48e2084981fa0d Mon Sep 17 00:00:00 2001 From: manyatiwari799 <104717674+manyatiwari799@users.noreply.github.com> Date: Sun, 15 May 2022 14:07:26 +0530 Subject: [PATCH 1/2] Update functions-and-arrays.js --- src/functions-and-arrays.js | 137 ++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index 18c9498..c9c8db5 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -61,3 +61,140 @@ const matrix = [ [24, 55, 58, 05, 66, 73, 99, 26, 97, 17], [21, 36, 23, 09, 75, 00, 76, 44, 20, 45] ]; +function greatestOfTwoNumbers(){ + var num1 = parseInt(document.getElementById("n1").value); + var num2 = parseInt(document.getElementById("n2").value); + if(num1 > num2) + document.getElementById("max").innerText = num1; + else + document.getElementById("max").innerText = num2; +} + +// The lengthy word +function findScaryWord(){ + const words = ['George', 'Alice', 'Alex', 'John', 'Infanta', 'Xavior', 'LourdhAntony']; + let longest = ""; + for(let i=0; i longest.length) + longest = words[i]; + } + document.getElementById("lengthy").innerText = longest; +} + +// Net Price +function netPrice(){ + const prices = [200, 120, 100, 108, 135, 162, 25, 170, 80, 110]; + let sum = 0; + for(let i=0; i= 0){ + result = arr[i][j] * arr[i][j-1] + * arr[i][j-2] * arr[i][j-3]; + if(max < result) + max = result; + } + + if((i-3) >= 0){ + result = arr[i][j] * arr[i-1][j] + * arr[i-2][j] * arr[i-3][j]; + if(max < result) + max = result; + } + + if((i-3) >= 0 && (j-3) >= 0){ + result = arr[i][j] * arr[i-1][j-1] + * arr[i-2][j-2] * arr[i-3][j-3]; + if(max < result) + max = result; + } + + if((i-3) >= 0 && (j-1) <= 0){ + result = arr[i][j] * arr[i-1][j+1] + * arr[i-2][j+2] * arr[i-3][j+3]; + if(max < result) + max = result; + } + } + } + return max; + } + + let n = 5; + let arr = [[ 1, 2, 3, 4, 5], + [ 1, 25, 3, 4, 5], + [ 1, 20, 3, 4, 5], + [ 1, 20, 3, 4, 5], + [ 1, 4, 3, 4, 5]]; + + document.getElementById("maxP").innerText = findMaxP(arr, n); +} From 8004a6ee0f0057bb3f97b392380ecf5b3ecf08b1 Mon Sep 17 00:00:00 2001 From: manyatiwari799 <104717674+manyatiwari799@users.noreply.github.com> Date: Sun, 15 May 2022 14:24:32 +0530 Subject: [PATCH 2/2] Update functions-and-arrays.js --- src/functions-and-arrays.js | 306 ++++++++++++++++++++---------------- 1 file changed, 169 insertions(+), 137 deletions(-) diff --git a/src/functions-and-arrays.js b/src/functions-and-arrays.js index c9c8db5..1912671 100644 --- a/src/functions-and-arrays.js +++ b/src/functions-and-arrays.js @@ -1,17 +1,127 @@ // Progression #1: Greatest of the two numbers +function greatestOfTwoNumbers(num1,num2) +{ + if(num1>num2) + { + return num1; + } + else if(num2>num1) + { + return num2; + } + else{ + return num1; + } +} + + + + // Progression #2: The lengthy word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; +function findScaryWord(words){ + if(words.length==0){ + return null; + } + else if(words.length==1){ + return words[0]; + } + else if(words.length==2){ + if(words[0].length==words[1].length){ + return words[0]; + } + } + else if(words.length>2){ + for(i=0;i num2) - document.getElementById("max").innerText = num1; - else - document.getElementById("max").innerText = num2; -} - -// The lengthy word -function findScaryWord(){ - const words = ['George', 'Alice', 'Alex', 'John', 'Infanta', 'Xavior', 'LourdhAntony']; - let longest = ""; - for(let i=0; i longest.length) - longest = words[i]; - } - document.getElementById("lengthy").innerText = longest; -} - -// Net Price -function netPrice(){ - const prices = [200, 120, 100, 108, 135, 162, 25, 170, 80, 110]; - let sum = 0; - for(let i=0; i= 0){ - result = arr[i][j] * arr[i][j-1] - * arr[i][j-2] * arr[i][j-3]; - if(max < result) - max = result; - } - - if((i-3) >= 0){ - result = arr[i][j] * arr[i-1][j] - * arr[i-2][j] * arr[i-3][j]; - if(max < result) - max = result; - } - - if((i-3) >= 0 && (j-3) >= 0){ - result = arr[i][j] * arr[i-1][j-1] - * arr[i-2][j-2] * arr[i-3][j-3]; - if(max < result) - max = result; - } - - if((i-3) >= 0 && (j-1) <= 0){ - result = arr[i][j] * arr[i-1][j+1] - * arr[i-2][j+2] * arr[i-3][j+3]; - if(max < result) - max = result; - } - } - } - return max; - } - - let n = 5; - let arr = [[ 1, 2, 3, 4, 5], - [ 1, 25, 3, 4, 5], - [ 1, 20, 3, 4, 5], - [ 1, 20, 3, 4, 5], - [ 1, 4, 3, 4, 5]]; - - document.getElementById("maxP").innerText = findMaxP(arr, n); -}