-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Paris Cécile et Régis #613
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,6 +1,20 @@ | ||
// Find the maximum | ||
|
||
// Finding Longest Word | ||
|
||
function maxOfTwoNumbers (num1, num2) { | ||
if (num1 > num2) { | ||
|
||
return num1; | ||
} | ||
|
||
else { | ||
|
||
return num2; | ||
} | ||
} | ||
|
||
|
||
// -----------------Finding Longest Word | ||
var words = [ | ||
'mystery', | ||
'brother', | ||
|
@@ -11,15 +25,62 @@ var words = [ | |
'crackpot' | ||
]; | ||
|
||
// Calculating a Sum | ||
function findLongestWord (array) { | ||
|
||
var longestWord = array[0]; | ||
|
||
array.forEach (function(element) { | ||
|
||
if(element.length > longestWord.length){ | ||
|
||
longestWord = element; | ||
} | ||
}); | ||
return longestWord; | ||
} | ||
|
||
findLongestWord (words); | ||
|
||
|
||
|
||
// -----------------Calculating a Sum | ||
|
||
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
|
||
// Calculate the Average | ||
function sumArray (array) { | ||
var theSum = 0; | ||
|
||
array.forEach (function(element) { | ||
theSum += element; | ||
}) | ||
return theSum; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// -----------------Calculate the Average | ||
|
||
var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
|
||
// Array of Strings | ||
function averageNumbers (array) { | ||
var theSum = 0; | ||
if(array.length === 0) { | ||
return undefined; | ||
} | ||
|
||
else { | ||
array.forEach (function(element) { | ||
theSum += element; | ||
}) | ||
} | ||
return theSum/array.length; | ||
} | ||
|
||
// -----------------Array of Strings | ||
var wordsArr = [ | ||
'seat', | ||
'correspond', | ||
|
@@ -33,6 +94,21 @@ var wordsArr = [ | |
'palace' | ||
]; | ||
|
||
function averageWordLength (array) { | ||
var length = 0; | ||
if(array.length === 0) { | ||
return undefined; | ||
} | ||
|
||
else { | ||
array.forEach (function(element) { | ||
length += element.length; | ||
}) | ||
} | ||
return length/array.length; | ||
|
||
} | ||
|
||
// Unique Arrays | ||
var wordsUnique = [ | ||
'crab', | ||
|
@@ -48,6 +124,34 @@ var wordsUnique = [ | |
'bring' | ||
]; | ||
|
||
|
||
function uniquifyArray (array) { | ||
var newArray = []; | ||
if(array.length === 0) { | ||
return undefined; | ||
} | ||
|
||
else { | ||
newArray.push (array[0]); | ||
|
||
for (var i=1; i< array.length; i++){ | ||
for (var j=0; j<newArray.length; j++){ | ||
if (array[i] !== newArray[j]) { | ||
newArray.push(array[i]); | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
if (newArray.length === array.length){ | ||
return array; | ||
} | ||
else{ | ||
return newArray; | ||
} | ||
} | ||
|
||
// Finding Elements | ||
var wordsFind = [ | ||
'machine', | ||
|
@@ -60,6 +164,20 @@ var wordsFind = [ | |
'disobedience' | ||
]; | ||
|
||
|
||
|
||
function doesWordExist (array, word) { | ||
|
||
var temp = false; | ||
|
||
for (var i=0; i<array.length; i++) { | ||
if (array[i] === word){ | ||
temp= true; | ||
} | ||
} | ||
return temp; | ||
} | ||
|
||
// Counting Repetion | ||
var wordsCount = [ | ||
'machine', | ||
|
@@ -74,8 +192,43 @@ var wordsCount = [ | |
'disobedience', | ||
'matter' | ||
]; | ||
|
||
|
||
function howManyTimes (array, word) { | ||
|
||
var counter = 0; | ||
|
||
if (array.length === 0){ | ||
return false; | ||
} | ||
else { | ||
for (var i=0; i< array.length; i++) { | ||
if (array[i] === word) { | ||
counter ++; | ||
} | ||
} | ||
} | ||
return counter; | ||
} | ||
// Bonus Quest | ||
|
||
function countUp (mat, x, y){ | ||
count = 0; | ||
for (var i=0; i<4; i++) { | ||
count *= mat[i][y]; | ||
} | ||
return count; | ||
} | ||
|
||
|
||
function greatestProduct (array) { | ||
var temp =0; | ||
|
||
|
||
|
||
return temp; | ||
} | ||
|
||
var matrix = [ | ||
[8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8], | ||
[49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the correction for the Matrix:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's globally well done! The code is clean and not too long. 💪 Keep up the good work! |
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a for loop IN a for loop, is quite risky.. specially when you have a much more simple way to do it.
You can use 2 methods:
indexOf :
array.indexOf("Word") => will return the index of Word in the array if Word exists, or return -1 if the word doesn't exist. If it returns an index, you shouldnt push, if it returns -1 then you should push it.
Includes:
array.includes("Word") => will return TRUE if word exists, or FALSE if it doesnt exist. Push when its false.
example with the indexOf :
Hope it's clear :)