-
Notifications
You must be signed in to change notification settings - Fork 51
BCN-PT- Antonio Rivera #8
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 1 commit
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "type": "chrome", | ||
| "request": "launch", | ||
| "name": "Launch Chrome against localhost", | ||
| "url": "http://localhost:8080", | ||
| "webRoot": "${workspaceFolder}" | ||
| } | ||
| ] | ||
| } |
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,5 +1,14 @@ | ||
| // Find the maximum | ||
|
|
||
| function maxOfTwoNumbers(num1, num2) { | ||
| if (num1 > num2) { | ||
| return num1; | ||
| } else { | ||
| return num2; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // Finding Longest Word | ||
| var words = [ | ||
| 'mystery', | ||
|
|
@@ -8,17 +17,66 @@ var words = [ | |
| 'crocodile', | ||
| 'pearl', | ||
| 'orchard', | ||
| 'crackpot' | ||
| 'crackpot', | ||
| ]; | ||
|
|
||
| function findLongestWord(arr) { | ||
| if (arr && arr.length == 0) { | ||
| return undefined; | ||
| } | ||
|
|
||
| var maxLength = 0; | ||
| var maxValueIndex = 0 | ||
|
|
||
| arr.forEach(function (newValue, newIndex) { | ||
| if (newValue.length > maxLength && newValue.split[" "].length > 0) { | ||
| var maxLength = newValue.length; | ||
| var maxValueIndex = newIndex; | ||
| } | ||
| }); | ||
| return arr[maxValueIndex]; | ||
|
|
||
| } | ||
|
|
||
| // Calculating a Sum | ||
|
|
||
| var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
|
|
||
| function sumArray(arr) { | ||
| var sum = 0; | ||
| for (var i = 0, total = arr.length; i < total; i++) { | ||
| var value = arr[i]; | ||
| if (isNaN(value)) { | ||
| var value = 0; | ||
| } | ||
| var sum = sum + value; | ||
| } | ||
| return sum; | ||
| } | ||
|
|
||
|
|
||
| // Calculate the Average | ||
|
|
||
| var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
|
|
||
| function averageNumbers(arr) { | ||
|
|
||
| if (arr && arr.length == 0) { | ||
| return undefined; | ||
| } | ||
|
|
||
| var sum = 0; | ||
| for (var i = 0, total = arr.length; i < total; i++) { | ||
| var value = arr[i]; | ||
| if (isNaN(value)) { | ||
| var value = 0; | ||
| } | ||
| var sum = sum + value; | ||
|
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. podrías reutilizar la función sumArray que has creado anteriormente |
||
| } | ||
| return sum / arr.length; | ||
| } | ||
|
|
||
|
|
||
| // Array of Strings | ||
| var wordsArr = [ | ||
| 'seat', | ||
|
|
@@ -33,6 +91,18 @@ var wordsArr = [ | |
| 'palace' | ||
| ]; | ||
|
|
||
| function averageWordLength(arr) { | ||
| if (arr && arr.length == 0) { | ||
| return undefined; | ||
| } | ||
| var newArrayValues = 0; | ||
|
|
||
| arr.forEach(function (newValue) { | ||
| newArrayValues = newArrayValues + newValue.length | ||
| }); | ||
| return newArrayValues / arr.length; | ||
| } | ||
|
|
||
| // Unique Arrays | ||
| var wordsUnique = [ | ||
| 'crab', | ||
|
|
@@ -48,6 +118,29 @@ var wordsUnique = [ | |
| 'bring' | ||
| ]; | ||
|
|
||
| function uniquifyArray(arr) { | ||
| if (arr && arr.length == 0) { | ||
| return undefined; | ||
| } | ||
|
|
||
| var totaArrLentWithDuplicates = arr.length | ||
| arr = newArr | ||
| for (i = 0; i < totaArrLentWithDuplicates; i++) { | ||
| for (j = 0; j < totaArrLentWithDuplicates; j++) { | ||
| if (arr[i] == arr[j]) { | ||
| arr.splice(i, 1); | ||
| } | ||
| } | ||
| } | ||
| if (totaArrLentWithDuplicates === arr.length) { | ||
| return arr; | ||
| } else { | ||
| return newArr; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| // Finding Elements | ||
| var wordsFind = [ | ||
| 'machine', | ||
|
|
@@ -60,6 +153,27 @@ var wordsFind = [ | |
| 'disobedience' | ||
| ]; | ||
|
|
||
| function doesWordExist(arr, word) { | ||
| if (arr && arr.length == 0) { | ||
| return false; | ||
| } | ||
| var wordRepit = 0 | ||
| arr.forEach(function (value) { | ||
| if (word === value) { | ||
| wordRepit = wordRepit + 1; | ||
| } | ||
| }) | ||
| if (wordRepit == 1 || arr.length == 1) { | ||
| return true; | ||
| } else if (wordRepit >= 1) { | ||
| return true; | ||
| } else if (wordRepit == 0) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| doesWordExist() | ||
|
|
||
| // Counting Repetion | ||
| var wordsCount = [ | ||
| 'machine', | ||
|
|
@@ -74,8 +188,39 @@ var wordsCount = [ | |
| 'disobedience', | ||
| 'matter' | ||
| ]; | ||
|
|
||
| function howManyTimes(arr, word) { | ||
| if (arr && arr.length == 0) { | ||
| return false; | ||
| } | ||
|
|
||
| var wordRepit = 0 | ||
| arr.forEach(function (value) { | ||
| if (word === value) { | ||
| wordRepit = wordRepit + 1; | ||
| } | ||
| }) | ||
| if (wordRepit == 1) { | ||
| return wordRepit; | ||
| } else if (wordRepit == 0) { | ||
| return wordRepit; | ||
| } else if (wordRepit == 5) { | ||
| return wordRepit; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| howManyTimes(wordsCount, 'eating') | ||
|
|
||
|
|
||
|
|
||
|
|
||
| // Bonus Quest | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| 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], | ||
|
|
@@ -97,4 +242,4 @@ var matrix = [ | |
| [20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 4, 36, 16], | ||
| [20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54], | ||
| [1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48] | ||
| ]; | ||
| ]; | ||
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.
que sentido tiene esta condición?? además siempre con 3 caracteres!