Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MADPT-Angel-Moya #167

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
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 11 starter-code/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"env": {
"es6": true,
"browser": true,
"jquery": true
},
"extends": "eslint:recommended",
"rules": {
"no-console": 0
}
}
104 changes: 96 additions & 8 deletions 104 starter-code/functions-and-arrays.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
// Find the maximum
function maxOfTwoNumbers (first, second) {

if(first > second) {
return first;
}
else if(second > first) {
return second;
}
else {
console.log("The numbers are equal: " + first);
return first;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Está genial, pero si utilizas el operador ternario ya lo clavas ;)
el operador ternario te lo recuerdo: condicion ? EstoPasaSiEsTrue : EstoPasaSiEsFalse


var largest = maxOfTwoNumbers(2, 6);
console.log(largest);

// Finding Longest Word
/* Con un for
function findLongestWord (words) {
var longestWord = "";
for(var i = 0; i < words.length; i++) {
if(words[i].length > longestWord.length) {
longestWord = words[i];
}
}
return longestWord;
}
*/

// Finding Longest Word
// Con un forEach
function findLongestWord (words) {
var longestWord = "";
words.forEach(function(element) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Así me gusta espartano!!! 👍 probando varias formas de hacer lo mismo.

Así es como se aprende !!! 💯

if(element.length > longestWord.length) {
longestWord = element;
}
}, this);
return longestWord;
}

var words = [
Expand All @@ -25,7 +54,11 @@ console.log(longest);

// Calculating a Sum
function sumArray (array) {

var sum = 0;
array.forEach(function(number){
sum += number;
});
return sum;
}

var numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10];
Expand All @@ -34,16 +67,20 @@ console.log(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(average);

// Array of Strings
function averageWordLength (array) {

function averageWordLength (array) {
var arrayLengths = [];
array.forEach(function(element){
arrayLengths.push(element.length);
});
return averageNumbers(arrayLengths);
}

var words = [
Expand All @@ -62,8 +99,25 @@ var averageLength = averageWordLength(words);
console.log(averageLength);

// Unique Arrays
/* Para explicar
function uniquifyArray (array) {
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
var unique = array.filter( onlyUnique );
return unique;
}
*/

// Unique Arrays
function uniquifyArray (array) {
var arrayUnique = [];
array.forEach(function(element){
if (arrayUnique.indexOf(element) == -1) {
arrayUnique.push(element);
}
});
return arrayUnique;
}

var words = [
Expand All @@ -84,7 +138,16 @@ console.log(uniqued);

// Finding Elements
function doesWordExist (wordsArray, word) {

var response = false;
for( var i = 0; i < wordsArray.length; i++) {
if(wordsArray[i] === word) {
response = true;
// En cuanto haya una coincidencia salimos
// Tambien podemos pasar antes por uniquifyArray para eliminar duplicados
break;
}
}
return response;
}

var words = [
Expand All @@ -106,7 +169,13 @@ console.log(hasDog);

// Counting Repetion
function howManyTimes (words, word) {

var numOcurrences = 0;
for( var i = 0; i < words.length; i++) {
if(words[i] === word) {
numOcurrences += 1;
}
}
return numOcurrences;
}

var words = [
Expand All @@ -131,7 +200,26 @@ console.log(howManyDog);

// Bonus Quest
function greatestProduct (matrix) {

var maxProduct = 0;
for (var i = 0; i < matrix.length; i++) {
for (var j = 0; j < matrix[i].length; j++) {
var center, up, down, left, right;
center = matrix[i][j];
matrix[i-1] ? up = matrix[i-1][j] : up = 1;
matrix[i+1] ? down = matrix[i+1][j] : down = 1;
matrix[i][j-1] ? left = matrix[i][j-1] : left = 1;
matrix[i][j+1] ? right = matrix[i][j+1] : right = 1;
var product = center * up * down * left * right;
//(product > maxProduct) ? maxProduct = product : maxProduct = maxProduct;
if (product > maxProduct) {
maxProduct = product;
var indiceI = i;
var indiceJ = j;
}
}
}
//console.log("POSICION CENTRAL es: [" + indiceI + "]" + "[" + indiceJ + "]" + " = " + matrix[indiceI][indiceJ]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Muy muy bien hecho el Bonus!! Enhorabuena!! Gran entrega del ejercicio.

return maxProduct;
}

var matrix = [
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.