- Notifications
You must be signed in to change notification settings - Fork381
VITFED028#79
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
Sucheta1402 wants to merge1 commit intoprograd-org:masterChoose a base branch fromSucheta1402: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
VITFED028#79
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
1 change: 1 addition & 0 deletionslab-javascript-functions-and-arrays
Submodule lab-javascript-functions-and-arrays added at 284223
235 changes: 196 additions & 39 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,220 @@ | ||
// Progression #1: Greatest of the two numbers | ||
function greatestOfTwoNumbers(x, y) { | ||
if (x > y) return x; | ||
else return y; | ||
} | ||
// Progression #2: The lengthy word | ||
const words = [ | ||
"mystery", | ||
"brother", | ||
"aviator", | ||
"crocodile", | ||
"pearl", | ||
"orchard", | ||
"crackpot", | ||
]; | ||
function findScaryWord(words) { | ||
let max = 0, | ||
final = null; | ||
for (let i = 0; i < words.length; i++) { | ||
if (words[i].length > max) { | ||
max = words[i].length; | ||
final = words[i]; | ||
} | ||
} | ||
return final; | ||
} | ||
// console.log(findScaryWord(words)); | ||
// Progression #3: Net Price | ||
const prices = [200, 120, 100, 108, 135, 162, 25, 170, 80, 110]; | ||
function netPrice(prices) { | ||
let sum = 0; | ||
for (let i = 0; i < prices.length; i++) { | ||
sum += prices[i]; | ||
} | ||
return sum; | ||
} | ||
// Progression #3.1 (Bonus): A generic sum() function | ||
function add(mixedArr) { | ||
let sum = 0; | ||
for (let i = 0; i < mixedArr.length; i++) { | ||
if (typeof mixedArr[i] == "number") sum += mixedArr[i]; | ||
else if (typeof mixedArr[i] == "string") sum += mixedArr[i].length; | ||
else if (typeof mixedArr[i] == "boolean") { | ||
if (mixedArr[i] == true) sum++; | ||
} else { | ||
throw new Error("Unsupported data type sir or ma'am"); | ||
} | ||
} | ||
return sum; | ||
} | ||
const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
// Progression #4: Calculate the average | ||
function midPointOfLevels(numbers) { | ||
if (numbers.length == 0) return null; | ||
let sum = 0; | ||
for (let i = 0; i < numbers.length; i++) { | ||
sum += numbers[i]; | ||
} | ||
let num = numbers.length; | ||
return sum / num; | ||
} | ||
// Progression 4.1: Array of numbers | ||
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
// Progression 4.2: Array of strings | ||
const wordsArr = [ | ||
"seat", | ||
"correspond", | ||
"linen", | ||
"motif", | ||
"hole", | ||
"smell", | ||
"smart", | ||
"chaos", | ||
"fuel", | ||
"palace", | ||
]; | ||
function averageWordLength(wordsArr) { | ||
if (wordsArr.length == 0) return null; | ||
let sum = 0; | ||
for (let i = 0; i < wordsArr.length; i++) { | ||
sum = sum + wordsArr[i].length; | ||
} | ||
return sum / wordsArr.length; | ||
} | ||
// Progression #4.3 (Bonus): A generic avg() function | ||
function avg(mixedArr) { | ||
if (mixedArr.length == 0) return null; | ||
let sum = 0; | ||
for (let i = 0; i < mixedArr.length; i++) { | ||
if (typeof mixedArr[i] == "number") sum += mixedArr[i]; | ||
else if (typeof mixedArr[i] == "string") sum += mixedArr[i].length; | ||
else if (typeof mixedArr[i] == "boolean") { | ||
if (mixedArr[i] == true) sum++; | ||
} else { | ||
throw new Error("Unsupported data type sir or ma'am"); | ||
} | ||
} | ||
sum = sum / mixedArr.length; | ||
return Math.round((sum + Number.EPSILON) * 100) / 100; | ||
} | ||
// Progression #5: Unique arrays | ||
const wordsUnique = ["bread", "flour"]; | ||
function uniqueArray(wordsUnique) { | ||
if (wordsUnique.length == 0) return null; | ||
unique = [...new Set(wordsUnique)]; | ||
return unique; | ||
} | ||
// Progression #7: Count repetition | ||
const wordsFind = [ | ||
"machine", | ||
"subset", | ||
"trouble", | ||
"starting", | ||
"matter", | ||
"eating", | ||
"truth", | ||
"disobedience", | ||
]; | ||
function searchElement(wordsFind, word) { | ||
if (wordsFind.length == 0) return null; | ||
let res = false; | ||
for (let i = 0; i < wordsFind.length; i++) { | ||
if (wordsFind[i] == word) res = true; | ||
} | ||
return res; | ||
} | ||
// Progression #7: Count repetition | ||
const wordsCount = ["machine", "matter"]; | ||
function howManyTimesElementRepeated(wordsCount, word) { | ||
let count = 0; | ||
for (let i = 0; i < wordsCount.length; i++) { | ||
if (wordsCount[i] == word) count++; | ||
} | ||
return count; | ||
} | ||
const matrix = [ | ||
[08, 02, 22, 97, 38, 15, 00, 40, 00, 75], | ||
[24, 55, 58, 05, 66, 73, 99, 26, 97, 17], | ||
[21, 36, 23, 09, 75, 00, 76, 44, 20, 45], | ||
]; | ||
function maximumProduct(matrix) { | ||
let prod = 0, | ||
max = 0; | ||
for (let i = 0; i < 7; i++) { | ||
for (let y = 0; y < 7; y++) { | ||
prod = | ||
matrix[i][y] * matrix[i][y + 1] * matrix[i][y + 2] * matrix[i][y + 3]; | ||
if (prod > max) max = prod; | ||
} | ||
} | ||
for (let y = 0; y < 7; y++) { | ||
for (let i = 0; i < 7; i++) { | ||
prod = | ||
matrix[i][y] * matrix[i + 1][y] * matrix[i + 2][y] * matrix[i + 3][y]; | ||
if (prod > max) max = prod; | ||
} | ||
} | ||
return max; | ||
} |
1 change: 1 addition & 0 deletionssrc/lab-cricpro-scoreboard
Submodule lab-cricpro-scoreboard added at 14b891
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.