- Notifications
You must be signed in to change notification settings - Fork6.7k
MAD Verónica y Raquel#108
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
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
69 changes: 52 additions & 17 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,27 @@ | ||
// Find the maximum | ||
function maxOfTwoNumbers (first, second) { | ||
if(first > second){ | ||
return first; | ||
}else{ | ||
return second; | ||
} | ||
} | ||
var largest = maxOfTwoNumbers(2,1); | ||
console.log("Maximum number: " +largest); | ||
// Finding Longest Word | ||
function findLongestWord (words) { | ||
var sizeWords = words[0].length; | ||
for(var i=1; i<words.length; i++){ | ||
if(words[i].length > sizeWords){ | ||
sizeWords = words[i].length; | ||
longestWord = words[i]; | ||
} | ||
} | ||
return longestWord; | ||
} | ||
var words = [ | ||
@@ -21,29 +34,38 @@ var words = [ | ||
"crackpot" | ||
]; | ||
var longest = findLongestWord(words); | ||
console.log("Longest word: " +longest); | ||
// Calculating a Sum | ||
function sumArray (array) { | ||
var total = array.reduce(function(sum, value) { | ||
return sum + value; | ||
}, 0); | ||
return total; | ||
} | ||
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
var total = sumArray(numbers); | ||
console.log("Array sum: "+total); | ||
// Calculate the Average | ||
function averageNumbers (array) { | ||
return sumArray(array)/array.length; | ||
} | ||
var numbers = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
var average = averageNumbers(numbers); | ||
console.log("Array average: " +average); | ||
// Array of Strings | ||
function averageWordLength (array) { | ||
var size = 0; | ||
array.forEach(function(name){ | ||
size += name.length | ||
}) | ||
return size/array.length; | ||
} | ||
var words = [ | ||
@@ -59,11 +81,18 @@ var words = [ | ||
"palace" | ||
]; | ||
var averageLength = averageWordLength(words); | ||
console.log("Average length: " +averageLength); | ||
// Unique Arrays | ||
function uniquifyArray (array) { | ||
var newArray= []; | ||
for (var i=0,idx=0;i< array.length;i++){ | ||
idx = newArray.indexOf(array[i]); | ||
if (idx== -1){ | ||
newArray.push(array[i]); | ||
} | ||
} | ||
return newArray; | ||
} | ||
var words = [ | ||
@@ -80,11 +109,11 @@ var words = [ | ||
"bring" | ||
]; | ||
var uniqued = uniquifyArray(words); | ||
console.log("Unique array:",uniqued); | ||
// Finding Elements | ||
function doesWordExist (wordsArray, word) { | ||
return wordsArray.includes(word); | ||
} | ||
var words = [ | ||
@@ -99,13 +128,19 @@ var words = [ | ||
]; | ||
var hasMatter = doesWordExist(words, "matter"); | ||
console.log("Does word exist? (matter):" +hasMatter); | ||
var hasDog = doesWordExist(words, "dog"); | ||
console.log("Does word exist? (dog):" +hasDog); | ||
// Counting Repetion | ||
function howManyTimes (words, word) { | ||
for (var count=0,i=0; i< words.length; i++){ | ||
if(words[i] === word){ | ||
count+=1; | ||
} | ||
} | ||
return count; | ||
} | ||
@@ -124,10 +159,10 @@ var words = [ | ||
]; | ||
var howManyMatter = howManyTimes(words, "matter"); | ||
console.log("How many words (matter):" +howManyMatter); | ||
var howManyDog = howManyTimes(words, "dog"); | ||
console.log("How many words (dog):" +howManyDog); | ||
// Bonus Quest | ||
function greatestProduct (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. ¿Que ha pasado? ¿No habéis podido salir de Matrix? Es broma chicas!!! Excelente trabajo!! | ||
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.