Skip to content

WEB-PT2 Gladys Alvarez#731

Closed
gladysaj wants to merge 1 commit into
ironhack-labs:masterfrom
gladysaj:master
Closed

WEB-PT2 Gladys Alvarez#731
gladysaj wants to merge 1 commit into
ironhack-labs:masterfrom
gladysaj:master

Conversation

@gladysaj
Copy link
Copy Markdown

@gladysaj gladysaj commented Feb 8, 2020

  • Struggling with loops with strings (index)
  • Couldn't quit spaces to count the paragraph

Copy link
Copy Markdown

@ta-web-mexpt2 ta-web-mexpt2 left a comment

Choose a reason for hiding this comment

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

Excelente Trabajo 👍

Comment thread js/index.js
let loremParagraph = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sapien ipsum, luctus et erat quis, eleifend aliquam elit. Sed laoreet lacus auctor ligula sollicitudin ullamcorper. Integer in sollicitudin augue. Sed ligula ex, hendrerit a velit ut, ultrices vulputate magna. Duis sagittis nisi in massa varius, in maximus risus tempor. Morbi at quam nec ligula pretium feugiat quis vel tortor. Vivamus feugiat pharetra risus. Duis vel euismod leo, sed blandit sem. Aenean sit amet massa vel turpis egestas viverra nec sodales enim. Quisque ultricies elementum orci, a ullamcorper metus efficitur gravida. Morbi auctor, nulla non volutpat porta, neque nisi sodales lacus, fermentum eleifend odio dolor quis erat. Nullam nec felis vehicula, ullamcorper arcu non, porttitor eros. Quisque bibendum semper eleifend. Quisque rhoncus diam vel nisi feugiat, in mollis turpis vulputate. Donec feugiat nisi in eros finibus, in consectetur est tempor. Sed a urna eu neque sollicitudin posuere et et orci. Maecenas interdum vestibulum cursus. Proin nec pulvinar leo. Nulla lobortis rhoncus scelerisque. Pellentesque venenatis vehicula risus, non mattis lorem egestas nec. Fusce vel tellus a felis auctor pretium sit amet et quam. Donec et egestas diam. Nam vitae risus quis neque posuere porta. Aliquam varius leo et viverra viverra.Integer id lobortis nisi. Duis ornare mauris id quam aliquam feugiat. Sed auctor id metus ut placerat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nam ultricies elit ut neque sollicitudin sodales. Phasellus et facilisis arcu, ut porta elit. Fusce et lobortis nibh, eget pharetra ante. Sed non facilisis augue. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse pretium imperdiet massa ac interdum. Nullam eu efficitur tellus. Sed at semper odio. Vivamus dolor dolor, venenatis et ex id, aliquam molestie ante. Mauris sem est, varius quis gravida vel, dignissim ac leo. Vivamus quis ligula eu eros egestas hendrerit id et justo."

// Make your program count the number of words in the string.
console.log(loremParagraph.length);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

aquí estamos mal porque con loremParagraph.length estamos contando hasta los espacios
entonces una solución seria convertir todo nuestro párrafo a un arreglo con .split(" ") para separar todo por espacios entonces nada mas nos quedaria algo así
let example = 'frase1 frase2' let splitExample = splitExample.split(" ") // ['frase1','frase2'] console.log(splitExample.length) // podemos usar .length tanto en string como en arreglos
con esto podremos saber cuantas palabras hay en nuestro párrafo

Comment thread js/index.js
console.log(loremParagraph.length);

// Make your program count the number of times the Latin word et appears.
console.log(loremParagraph.indexOf("et"));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

aquí lo que estamos haciendo es encontrando la posición de et y solos nos arroja 24 (index)

para esta solución lo haremos de una manera mas pro crearemos una función, convertiremos nuestro párrafo a un arreglo quitando los espacio y luego revisaremos con un for para encontrar la palabra 'et' y obtener el resultado
aquí cree una función en la cual recibe 2 parámetros
`
function word_count(str, word)
{
str = str.split(' ') // convierto mi frase en un arreglo separado por espacios
var word_Count = 0; // declaro un contador
for (var position = 0; position < str.length; position++) //revisamos la frase con un for para leer elemento por elemento
{
if (str[position] == word) //aquí leemos posición por posición y revisamos que sea igual a nuestra palabra a buscar, en caso de encontrarla le sumamos a nuestro contador un uno
{
word_Count += 1;
}
}
return word_Count; // regresa el numero de coincidencias encontradas
}

console.log(char_count(loremParagraph, 'et')); // aquí ejecutamos nuestra función y le pasamos los 2 parámetros el párrafo y la palabra a encontrar
`

Comment thread js/index.js
console.log(loremParagraph.indexOf("et"));

// Bonus2
// Create a new variable phraseToCheck and have it contain some string value. Write a code that will check if the value we assigned to this variable is a Palindrome.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

aqui te dejo un hack de como realizar este bonus no estan completo pero funciona

`
let originalP = phraseToCheck.split(' ').join('').toLowerCase()
let reversP= phraseToCheck.split(' ').join('')
reversP=reversP.split('').reverse().join('').toLowerCase()

if (originalP === reversP) {
console.log(Word ${phraseToCheck} is a Palindrome);
} else {
console.log(Word ${phraseToCheck} is not a Palindrome);
}

`

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants