- Notifications
You must be signed in to change notification settings - Fork380
VITFED16#94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
nirati16 wants to merge1 commit intoprograd-org:masterChoose a base branch fromnirati16:master
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
VITFED16#94
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletionsindex.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Arrays & Functions</title> | ||
| <script src="./src/functions-and-arrays.js"></script> | ||
| </head> | ||
| <body> | ||
| <!-- Greatest of the two --> | ||
| <h2>Greatest of the two</h2> | ||
| <input type="number" id="n1" placeholder="1st number"> | ||
| <input type="number" id="n2" placeholder="2nd number"> | ||
| <input type="submit" value="Submit" onclick="greatestOfTwoNumbers()"> | ||
| <span> Maximum: <span id="max"></span></span> | ||
| <!-- --> | ||
| <br><br><br><br> | ||
| <!-- The lengthy word --> | ||
| <h2>The lengthy word</h2> | ||
| <p style="font-size: larger;">Words are = 'George', 'Alice', 'Alex', 'John', 'Infanta', 'Xavior', 'LourdhAntony'</p> | ||
| <input type="submit" value="Submit" onclick="findScaryWord()"> | ||
| <span> Lengthy Word: <span id="lengthy"></span></span> | ||
| <!-- --> | ||
| <br><br><br><br> | ||
| <!-- Net Price --> | ||
| <h2>Net Price</h2> | ||
| <p style="font-size: larger;">Prices = 200, 120, 100, 108, 135, 162, 25, 170, 80, 110</p> | ||
| <input type="submit" value="Submit" onclick="netPrice()"> | ||
| <span> Net Price: <span id="net"></span></span> | ||
| <!-- --> | ||
| <br><br><br><br> | ||
| <!-- Mid Point --> | ||
| <h2>Mid Point</h2> | ||
| <h3>Array of Numbers (4.1)</h3> | ||
| <p style="font-size: larger;">Levels = 22, 16, 9, 10, 7, 14, 11, 9</p> | ||
| <input type="submit" value="Submit" onclick="midPointOfLevels()"> | ||
| <span> Average: <span id="avg"></span></span> | ||
| <br><br> | ||
| <h3>Array of Strings (4.2)</h3> | ||
| <p style="font-size: larger;">Items = 'bread', 'jam', 'milk', 'egg', 'flour', 'oil', 'rice', 'coffee powder', 'sugar', 'salt'</p> | ||
| <input type="submit" value="Submit" onclick="averageWordLength()"> | ||
| <span> Average WordLength: <span id="avg-str"></span></span> | ||
| <!-- --> | ||
| <br><br><br><br> | ||
| <!-- Unique arrays --> | ||
| <h3>Unique arrays</h3> | ||
| <p style="font-size: larger;">Items = 'bread', 'jam', 'milk', 'egg', 'flour', 'oil', 'rice', 'coffee powder', 'sugar', 'salt', 'egg', 'flour'</p> | ||
| <input type="submit" value="Submit" onclick="uniqueArray()"> | ||
| <span> Unique Array: <span id="unique"></span></span> | ||
| <!-- --> | ||
| <br><br><br><br> | ||
| <!-- Find elements --> | ||
| <h3>Find elements</h3> | ||
| <p style="font-size: larger;">Words = 'door', 'window', 'ceiling', 'roof', 'plinth', 'tiles', 'ceiling', 'flooring'</p> | ||
| <input type="text" id="str" placeholder="search element"> | ||
| <input type="submit" value="Submit" onclick="searchElement()"> | ||
| <span> Element present: <span id="found"></span></span> | ||
| <!-- --> | ||
| <br><br><br><br> | ||
| <!-- Count repeated elements --> | ||
| <h3>Count repeated elements</h3> | ||
| <p style="font-size: larger;">Words = 'machine', 'matter', 'subset', 'trouble', 'starting', 'matter', 'eating', 'matter', 'truth', 'disobedience', 'matter'</p> | ||
| <input type="submit" value="Submit" onclick="howManyTimesElementRepeated()"> | ||
| <p> Frequencies: <span id="freq"></span></p> | ||
| <!-- --> | ||
| <br><br><br> | ||
| <!-- Product of adjacent numbers --> | ||
| <h3>Product of adjacent numbers</h3> | ||
| <p style="font-size: larger;">Matrix = (5x5)<br> | ||
| [ 1, 2, 3, 4, 5] <br> | ||
| [ 1, 25, 3, 4, 5] <br> | ||
| [ 1, 20, 3, 4, 5] <br> | ||
| [ 1, 20, 3, 4, 5] <br> | ||
| [ 1, 4, 3, 4, 5] <br></p> | ||
| <input type="submit" value="Submit" onclick="maximumProduct()"> | ||
| <p> Max product: <span id="maxP"></span></p> | ||
| </body> | ||
| </html> |
201 changes: 138 additions & 63 deletionssrc/functions-and-arrays.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,63 +1,138 @@ | ||
| // greatestOfTwoNumbers | ||
| 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<words.length; i++){ | ||
| if(words[i].length > 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<prices.length; i++) | ||
| sum += prices[i]; | ||
| document.getElementById("net").innerText = sum; | ||
| } | ||
| // Mid Point | ||
| //4.1 | ||
| function midPointOfLevels(){ | ||
| const levels = [22, 16, 9, 10, 7, 14, 11, 9]; | ||
| let sum = 0; | ||
| for(let i=0; i<levels.length; i++){ | ||
| sum += levels[i]; | ||
| } | ||
| let average = sum / levels.length; | ||
| document.getElementById("avg").innerText = average; | ||
| } | ||
| //4.2 | ||
| function averageWordLength(){ | ||
| const items = ['bread', 'jam', 'milk', 'egg', 'flour', 'oil', 'rice', 'coffee powder', 'sugar', 'salt']; | ||
| let sum = 0; | ||
| for(let i=0; i<items.length; i++){ | ||
| let len = items[i].length; | ||
| sum += len; | ||
| } | ||
| let avg_str = sum / items.length; | ||
| document.getElementById("avg-str").innerText = avg_str; | ||
| } | ||
| // Unique arrays | ||
| function uniqueArray(){ | ||
| const items = ['bread', 'jam', 'milk', 'egg', 'flour', 'oil', 'rice', 'coffee powder', 'sugar', 'salt', 'egg', 'flour']; | ||
| let unique_arr = [...new Set(items)]; | ||
| document.getElementById("unique").innerText = unique_arr; | ||
| } | ||
| // Find elements | ||
| function searchElement(){ | ||
| const words = ['door','window','ceiling','roof','plinth','tiles','ceiling','flooring']; | ||
| let str = document.getElementById("str").value; | ||
| for(let i=0; i<words.length; i++){ | ||
| if(str == words[i]){ | ||
| document.getElementById("found").innerText = "True"; | ||
| break; | ||
| } | ||
| else | ||
| document.getElementById("found").innerText = "False"; | ||
| } | ||
| } | ||
| // Count repeated elements | ||
| function howManyTimesElementRepeated(){ | ||
| const words = ['machine', 'matter', 'subset', 'trouble', 'starting', 'matter', 'eating', 'matter', 'truth', 'disobedience', 'matter']; | ||
| var answer = []; | ||
| for(let i=0; i<words.length; i++){ | ||
| let f = 0; | ||
| let current = words[i]; | ||
| for(let j=0; j<words.length; j++) | ||
| if(current == words[j]) | ||
| f++; | ||
| answer.push(" " + words[i] + " - " + f + " "); | ||
| document.getElementById("freq").innerText = answer; | ||
| } | ||
| } | ||
| // Product of adjacent numbers | ||
| function maximumProduct(){ | ||
| function findMaxP(arr, n){ | ||
| let max = 0, result; | ||
| for(let i=0; i<n; i++){ | ||
| for(let j=0; j<n; j++){ | ||
| if((j-3) >= 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); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.