Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[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

Closed
moigarcia wants to merge14 commits intoironhack-labs:masterfrommoigarcia:master

Conversation

moigarcia
Copy link

@moigarciamoigarcia commentedOct 31, 2018
edited
Loading

Me he dejado el bonus.

fontcubertaand others added14 commitsJanuary 10, 2017 17:49
…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
Copy link

@plasoplaso left a 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 {

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 :)

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){

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){

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);

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){

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){

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){

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;}

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@plasoplasoplaso approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

8 participants
@moigarcia@plaso@mc100s@fontcuberta@nizaroni@ta-web-mad@papuarza@HectorBlisS

[8]ページ先頭

©2009-2025 Movatter.jp