-
Notifications
You must be signed in to change notification settings - Fork 6.7k
[MAD PP Ángel Pérez y Esperanza Amaya] #515
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
// Find the maximum | ||
function maxOfTwoNumbers (a, b) { | ||
if (a>b) { | ||
return a; | ||
} else if (b>a) { | ||
return b; | ||
} else { | ||
return a; | ||
} | ||
} | ||
|
||
// Finding Longest Word | ||
var words = [ | ||
|
@@ -11,14 +20,43 @@ var words = [ | |
'crackpot' | ||
]; | ||
|
||
function findLongestWord (array) { | ||
var longest = 0; | ||
for (var i = 0; i < array.length; i++) { | ||
if (array[i].length > longest) { | ||
longest = array[i].length; | ||
} | ||
return longest; | ||
} | ||
} | ||
|
||
|
||
// Calculating a Sum | ||
|
||
var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; | ||
|
||
function sumArray(array) { | ||
if (array !== "") { | ||
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. Os falla que no estáis retornando nada cuando hacéis el reduce, os faltaría después del else:
|
||
var result=array.reduce(function(a,b){ | ||
return a + b; | ||
}) | ||
} else { | ||
return 0; | ||
} | ||
}; | ||
|
||
// Calculate the Average | ||
|
||
var numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
|
||
function averageNumbers(array){ | ||
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. Os pasa lo mismo que en de arriba, también tenéis que controlar si el la variable result tiene valor para poder dividirla, porque sino os darían error. |
||
var result=array.reduce(function(a,b){ | ||
a + b; | ||
}) | ||
return result/array.length; | ||
} | ||
|
||
|
||
// Array of Strings | ||
var wordsArr = [ | ||
'seat', | ||
|
@@ -33,6 +71,14 @@ var wordsArr = [ | |
'palace' | ||
]; | ||
|
||
function averageWordLength(array) { | ||
var result=array.reduce(function(a,b){ | ||
a.length + b.length; | ||
}) | ||
return result/array.length; | ||
} | ||
|
||
|
||
// Unique Arrays | ||
var wordsUnique = [ | ||
'crab', | ||
|
@@ -48,6 +94,12 @@ var wordsUnique = [ | |
'bring' | ||
]; | ||
|
||
function uniquifyArray(array) { | ||
return (array.unique()); | ||
} | ||
|
||
|
||
|
||
// Finding Elements | ||
var wordsFind = [ | ||
'machine', | ||
|
@@ -60,6 +112,15 @@ var wordsFind = [ | |
'disobedience' | ||
]; | ||
|
||
function doesWordExist(argument, array){ | ||
for (i=0; i<array.length; i++){ | ||
if (argument == array[i]) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
|
||
// Counting Repetion | ||
var wordsCount = [ | ||
'machine', | ||
|
@@ -74,6 +135,16 @@ var wordsCount = [ | |
'disobedience', | ||
'matter' | ||
]; | ||
|
||
function howManyTimes(array, wordToSearch) { | ||
var n=0; | ||
for (i=0; i < array.length; i++) { | ||
if(array[i] == wordToSearch) { | ||
n++; | ||
} | ||
} | ||
} | ||
|
||
// Bonus Quest | ||
|
||
var matrix = [ | ||
|
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.
Os falla un pequeño detalla, en lugar de guardar la longitud del string si guardáis directamente el string y tambien tenéis el return dentro del for, si lo sacáis funcionaría.