- Notifications
You must be signed in to change notification settings - Fork6.7k
[PTMAD1018][MOISES GARCIA]#696
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.
Conversation
Removed duplicated text
Extra Resources added
…with-teststarter-code-with-tests
…one" but the test is expecting for the string itself, i change the Readme file wich is the quck fix, but may be could be good to change the spec file to not confuse the student.
…tion-fixthe test are waiting for undefined but the description says false
…rd-fixfind-longest-word-little-fix
plaso left a comment
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.
Muy bien Moisés, a seguir así!!!
function maxOfTwoNumbers (n1, n2){ | ||
if (n1 > n2){ | ||
return n1; | ||
} else { |
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.
Buen ejercicio Moisés! Vamos a ver cosillas a mejorar o otras formas de hacerlo:
Este else nos sobraría :)
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.
Otra forma:
function maxOfTwoNumbers(firstNumber, secondNumber) { return Math.max(firstNumber, secondNumber);}
} | ||
} | ||
function findLongestWord(words){ |
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.
Te dejo una solución usando map y dividiéndolo en dos funciones, porque la primera la reutilicé más tarde, ahora te muestro donde la repito.
function getWordsLength(words) { return words.map(function(word) { return word.length; });}function findLongestWord(words) { var wordsLength = getWordsLength(words); var maxLength = Math.max.apply(null, wordsLength); var indexMaxLength = wordsLength.indexOf(maxLength); return words[indexMaxLength]; }
} | ||
} | ||
function sumArray(numbers){ |
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.
Bien!! Usando reduce, perfecto.
function averageNumbers(numbersAvg){ | ||
if (numbersAvg == 0){ | ||
} else { | ||
var sumNumbers = numbersAvg.reduce(function(a, b){ return a + b; },0); |
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.
Pero aquí podemos reutilizar esa funcion de SumArray ;)
} | ||
} | ||
function averageWordLength(wordsArr){ |
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.
Aquí es donde yo reutilicé todas las funciones anteriores, te hago un recopilatorio de ellas:
function getWordsLength(words) { return words.map(function(word) { return word.length; });}
function sumArray(numbers) { return numbers.reduce(function(acc, current) { return acc + current; }, 0)}
function averageNumbers(numbers) { return numbers.length > 0 ? sumArray(numbers) / numbers.length : undefined;}
function averageWordLength(words) { var wordLengths = getWordsLength(words); return averageNumbers(wordLengths);}
} | ||
} | ||
function uniquifyArray(wordsUnique){ |
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.
Usando filter:
function uniquifyArray(words) { if (words.length > 0) { return words.filter(function(word, index) { var firstIndex = words.indexOf(word); var lastIndex = words.lastIndexOf(word); return firstIndex === lastIndex || (firstIndex !== lastIndex && index === firstIndex); }); }}
return wordRepeat.length; | ||
} | ||
function greatestProduct(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.
Ejemplo del bonus:
function greatestProduct(matrix) { var greatestProductNumber = 0; for (var i = 0; i < matrix.length; i++) { for (var j = 0; j < matrix[i].length; j++) { var numbersToMultiply = []; var positionsX = [j - 1, j + 1]; var positionsY = [i - 1, i + 1]; positionsX.forEach(function(position) { if (position >= 0 && position <= matrix[i].length) { numbersToMultiply.push(position, j); } }) positionsY.forEach(function(position) { if (position >= 0 && position <= matrix.length) { numbersToMultiply.push(i, position); } }) var currentNumberProduct = numbersToMultiply.reduce(function(acc, current) { if (current) { return acc * current; } return acc; }, 1); if (currentNumberProduct > greatestProductNumber) { greatestProductNumber = currentNumberProduct; } } } return greatestProductNumber;}
Uh oh!
There was an error while loading.Please reload this page.
Me he dejado el bonus.