Skip to content

Conversation

@joanadgomes
Copy link

No description provided.

Copy link

@webLisbonTA webLisbonTA left a comment

Choose a reason for hiding this comment

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

Good job on the lab and on the bonuses.


for (let i = 0; i < len / 2; i++) {

if (string[i] !== string[len - 1 - i]) {

Choose a reason for hiding this comment

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

Here, the loop is not working correctly.
Here's a solution that you could've use:

let stringToCheck = "A man, a plan, a canal, Panama!";
stringToCheck = stringToCheck.replace(/[ ,!.]/g, "").toLowerCase();
let reversedString = stringToCheck.split('').reverse().join('');
if (stringToCheck === reversedString) {
  console.log('String is a palindrome');
}
else {
  console.log('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