- Notifications
You must be signed in to change notification settings - Fork6.7k
BCN PT - Nuria Casas Crous#374
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
84 changes: 83 additions & 1 deletionstarter-code/src/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,4 +1,14 @@ | ||
// Find the maximum | ||
function maxOfTwoNumbers (a, b){ | ||
if (a > b){ | ||
return a; | ||
} | ||
else { | ||
return b; | ||
} | ||
} | ||
// Finding Longest Word | ||
var words = [ | ||
@@ -11,13 +21,44 @@ var words = [ | ||
'crackpot' | ||
]; | ||
function findLongestWord (arr) { | ||
var longest = '' | ||
if (arr.length === 0){ | ||
return | ||
} | ||
for (i=0; i < arr.length; i++) { | ||
if (arr[i].length > longest.length) { | ||
longest = arr[i]; | ||
} | ||
} | ||
return longest; | ||
} | ||
// Calculating a Sum | ||
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
function sumArray(arr){ | ||
if (arr.length === 0){ | ||
return sum = 0;} | ||
var sum = 0; | ||
for (i=0; i < arr.length; i++){ | ||
sum += arr[i]; | ||
} | ||
return 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. Recuerda tabular el código | ||
// Calculate the Average | ||
var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
function averageNumbers (arr){ | ||
if (arr.length === 0){ | ||
return} | ||
var average = sumArray(arr)/arr.length; | ||
return average; | ||
} | ||
// Array of Strings | ||
var wordsArr = [ | ||
@@ -32,6 +73,16 @@ var wordsArr = [ | ||
'fuel', | ||
'palace' | ||
]; | ||
function averageWordLength(arr){ | ||
if (arr.length === 0){ | ||
return} | ||
var wordLength = [] | ||
for (i=0; i < arr.length; i++) { | ||
wordLength.push(arr[i].length) | ||
} | ||
return averageNumbers(wordLength); | ||
} | ||
console.log(averageWordLength(wordsArr)); | ||
// Unique Arrays | ||
var wordsUnique = [ | ||
@@ -47,6 +98,17 @@ var wordsUnique = [ | ||
'simple', | ||
'bring' | ||
]; | ||
function uniquifyArray(arr){ | ||
if (arr.length === 0){ | ||
return} | ||
var newArray = []; | ||
for (i=0; i < arr.length; i++) { | ||
if (newArray.indexOf(arr[i]) === -1){ | ||
newArray.push(arr[i])} | ||
} | ||
return newArray; | ||
} | ||
// Finding Elements | ||
var wordsFind = [ | ||
@@ -59,7 +121,15 @@ var wordsFind = [ | ||
'truth', | ||
'disobedience' | ||
]; | ||
function doesWordExist (arr, word) { | ||
if (arr.length === 0){ | ||
return false;} | ||
for (i=0; i < arr.length ; i++) { | ||
if (arr[i] === word){ | ||
return true;} | ||
} | ||
return false; | ||
} | ||
// Counting Repetion | ||
var wordsCount = [ | ||
'machine', | ||
@@ -74,6 +144,18 @@ var wordsCount = [ | ||
'disobedience', | ||
'matter' | ||
]; | ||
function howManyTimes(arr,word){ | ||
var wordCount = []; | ||
if (arr.length === 0){ | ||
return false;} | ||
for (i=0; i < arr.length ; i++) { | ||
if (arr[i] === word){ | ||
wordCount.push(arr[i]); | ||
;} | ||
} | ||
return wordCount.length; | ||
} | ||
// Bonus Quest | ||
var 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.