- Notifications
You must be signed in to change notification settings - Fork6.7k
[MAD][WEB-PT1017][RAQUEL-FDEZ]#184
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
Closed
Uh oh!
There was an error while loading.Please reload this page.
Closed
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
65355c7
feat: add function maxOfTwoNumbers
originalrfr598f2ce
feat: add finding longest word
originalrfr92886c4
feat: add calculating a sum
originalrfref5b2e6
feat: add calculate the average level 1
originalrfr8948bb0
feat: add calculate the average level 2
originalrfr57859c7
feat: add unique arrays
originalrfr443a054
feat: add finding elements
originalrfrb49ddf4
feat: add Counting Repetion
originalrfrFile 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
Binary file added.DS_Store
Binary file not shown.
63 changes: 49 additions & 14 deletionsstarter-code/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,14 +1,16 @@ | ||
// Find the maximum | ||
function maxOfTwoNumbers (first, second) { | ||
return Math.max(first, second); | ||
} | ||
var largest = maxOfTwoNumbers(2, 6); | ||
console.log(largest); | ||
// The maximum number is 6 | ||
// Finding Longest Word | ||
function findLongestWord (words) { | ||
return words.sort(function (a, b) { return b.length - a.length; }); | ||
} | ||
var words = [ | ||
@@ -21,29 +23,36 @@ var words = [ | ||
"crackpot" | ||
]; | ||
var longest = findLongestWord(words); | ||
console.log(longest[0]); | ||
// The longest word is crocodile | ||
// Calculating a Sum | ||
function sumArray (array) { | ||
return array.reduce(function(a, b){ return a + b; }); | ||
} | ||
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
var total = sumArray(numbers); | ||
console.log(total); | ||
// The total sum is 87 | ||
// Calculate the Average: Level 1 | ||
function averageNumbers (array) { | ||
var sum = sumArray(numbers); | ||
return sum/numbers.length; | ||
} | ||
var numbers = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
var average = averageNumbers(numbers); | ||
console.log(average); | ||
// The averange is 6 | ||
// Calculate the Average: Level 2 | ||
function averageWordLength (array) { | ||
return array.reduce(function(a, b){ return a + b; }); | ||
} | ||
var words = [ | ||
@@ -59,11 +68,19 @@ var words = [ | ||
"palace" | ||
]; | ||
var averageLength = averageWordLength(words); | ||
console.log(averageWordLength(words).length/words.length); | ||
// The average letters of the words is 5.3 | ||
// Unique Arrays | ||
function uniquifyArray(array) { | ||
var newArray = []; | ||
array.forEach(function(indexValue) { | ||
if (newArray.indexOf(indexValue) === -1) { | ||
newArray.push(indexValue); | ||
} | ||
}); | ||
return newArray; | ||
} | ||
var words = [ | ||
@@ -82,10 +99,18 @@ var words = [ | ||
var uniqued = uniquifyArray(words); | ||
console.log(uniqued); | ||
// The new array is ['crab', 'poison', 'contagious', 'simple', 'bring', 'sharp', 'playground', 'communion'] | ||
// Finding Elements | ||
function doesWordExist (wordsArray, word) { | ||
var result = false; | ||
for (var i = 0; i < wordsArray.length; i++) { | ||
if (word === wordsArray[i]) { | ||
result = true; | ||
} | ||
} | ||
return result; | ||
} | ||
var words = [ | ||
"machine", | ||
@@ -104,9 +129,17 @@ console.log(hasMatter); | ||
var hasDog = doesWordExist(words, "dog"); | ||
console.log(hasDog); | ||
// Return true if it exists, otherwise return false. | ||
// Counting Repetion | ||
function howManyTimes (words, word) { | ||
count = 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. cuando quieras utilizar variables dentro de una función sólo, deberías declararlas dentro, con var por ejemplo | ||
index = words.indexOf(word); | ||
while ( index != -1 ) { | ||
count++; | ||
index = words.indexOf(word,index+1); | ||
} | ||
return count ; | ||
} | ||
var words = [ | ||
@@ -129,6 +162,8 @@ console.log(howManyMatter); | ||
var howManyDog = howManyTimes(words, "dog"); | ||
console.log(howManyDog); | ||
// Return the number of times that word appears in the array | ||
// Bonus Quest | ||
function greatestProduct (matrix) { | ||
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.