apaulineoliveira / verificador-de-palindromo

O programa verifica se dada palavra é um palíndromo (pode ser lida da mesma maneira mesmo que de trás para frente).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🎳 Objetivo

O intuito deste projeto foi criar um verificador de palíndromo. Ou seja, se as palavras colocadas no console podem ser lidas da mesma maneira de trás para frente. A exemplo da palavra "ovo". O resultado será um booleano (true ou false). Se nenhuma palavra for inserida o console irá retornar a mensagem: "string inexistente".

Para essa solução foram utilizados vários métodos em Js. Sendo eles:

  • split: Esse método divide uma string em uma lista ordenada de substrings. Coloca essas substrings em um arrray e em seguida retorna o respectivo array. A divisão é feita procurando um padrão, onde o padrão é fornecido.
  • reverse: Esse método inverte os itens de um array. O primeiro elemento do array se torna o último e o último torna-se o primeiro.
  • join: Esse método vai juntar todos os elementos do array em uma string.

Utilizando RegExp, toLowerCase e replace

A segunda solução que consta no arquivo: scripttwo.js possui alguns itens adicionais que deixam o código mais interessante e com respostas mais assertivas. Como a implementação do RegExp e do toLowerCase. O primeiro é utilizado para remover caracteres indesejados da string. O segundo, coloca a string em letras maiúsculas. O método replace foi utilizado para retornar uma nova string com alguma ou todas as correspondências substituídas por aquilo que foi sugerido, neste caso, foi usada a RegExp anteriormente criada.

Utilizando Loop

A terceira solução que consta no arquivo: script.three.js possui o mesmo escopo inicial, entretanto, é solucionada com o laço for. Possuindo como lógica central: enquanto os caracteres de cada parte corresponderem o laço for continuará; quando os caracteres pararem de corresponder será retornado false, ocorrendo então a saída do laço for.



🎳 Purpose

The goal of this project was to create a palindrome checker. That is, whether words placed on the console can be read the same way backwards. Like the word "egg". The result will be a boolean (true or false). If no word is entered, the console will return the message: "nonexistent string".

For this solution, several methods were used in Js. They being:

  • split: This method splits a string into an ordered list of substrings. Puts these substrings into an array and then returns the respective array. Splitting is done by looking for a pattern, where the pattern is given.
  • reverse: This method reverses the items of an array. The first array element becomes the last and the last becomes the first.
  • join: This method will join all elements of the array into a string.

Using RegExp, toLowerCase and replace

The second solution in the file: scripttwo.js has some additional items that make the code more interesting and with more assertive responses. Like the implementation of RegExp and toLowerCase. The first is used to remove unwanted characters from the string. The second, capitalizes the string. The replace method was used to return a new string with some or all matches replaced by what was suggested, in this case, the previously created RegExp was used.

Using Loop

The third solution in the file: script.three.js has the same initial scope, however, it is solved with the for loop. Its core logic is: as long as the characters in each part match, the for loop will continue; when the characters stop matching, false will be returned, and the for loop will exit.

About

O programa verifica se dada palavra é um palíndromo (pode ser lida da mesma maneira mesmo que de trás para frente).


Languages

Language:JavaScript 100.0%