- Notifications
You must be signed in to change notification settings - Fork6.7k
PAR Valérie Linarès & Shanshan Cao#414
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
// Find the maximum | ||
function maxOfTwoNumbers(num1, num2){ | ||
return Math.max(num1, num2); | ||
}; | ||
maxOfTwoNumbers(2,3); | ||
// Finding Longest Word | ||
var words = [ | ||
@@ -11,14 +16,45 @@ var words = [ | ||
'crackpot' | ||
]; | ||
function findLongestWord(target){ | ||
var sorted = target.sort( | ||
function(a, b){ | ||
return b.length - a.length;} | ||
); | ||
return sorted[0] | ||
}; | ||
findLongestWord(words); | ||
// Calculating a Sum | ||
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
var sum = 0; | ||
function sumArray(target){ | ||
var result = target.reduce(function(accumulator, currentValue, currentIndex, array) { | ||
| ||
return accumulator + currentValue; | ||
}); | ||
sum = result; | ||
return sum; | ||
} | ||
sumArray(numbers) | ||
// Calculate the Average | ||
var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
function averageNumbers(target){ | ||
sumArray(target); //get the sum | ||
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. Same here you should add a condition, so when target is empty you return undefined | ||
var len = target.length; //get the length | ||
var average = sum / len; //get the average | ||
return average; | ||
} | ||
averageNumbers(numbersAvg); | ||
// Array of Strings | ||
var wordsArr = [ | ||
'seat', | ||
@@ -33,6 +69,25 @@ var wordsArr = [ | ||
'palace' | ||
]; | ||
//console.log("sum starts at: " + sum); | ||
function averageWordLength(target){ | ||
var numberArray = []; //create empty array | ||
//console.log("numberArr starts at: "+ numberArray) | ||
target.forEach(function (i){ //loop every element, get len, push to the numberArr | ||
numberArray.push(i.length); | ||
}); | ||
//console.log("numberArr ends at:" + numberArray); | ||
sumArray(numberArray); //Update the sum value using the sum function | ||
//console.log("sum ends at: " + sum); | ||
averageNumbers(numberArray); //get average of numberArr | ||
} | ||
averageWordLength(wordsArr); | ||
// Unique Arrays | ||
var wordsUnique = [ | ||
'crab', | ||
@@ -48,6 +103,8 @@ var wordsUnique = [ | ||
'bring' | ||
]; | ||
// Finding Elements | ||
var wordsFind = [ | ||
'machine', | ||