Skip to content

Conversation

@SinTomas
Copy link

Labs Done by Tomás Maria and Roshan Pradhan.

Copy link

@brunorocha20 brunorocha20 left a comment

Choose a reason for hiding this comment

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

Nice work on the lab Tomás.

let firstHalf = phraseToCheck.slice(0,5);
let secondHalf = phraseToCheck.slice(5,10);
let reverseSecondHalf = "";

Choose a reason for hiding this comment

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

This is a cool way of logical thinking, however, it is not all correct. That just checks correctly words that are exactly 10 characters long.

A solution for that iteration is a bit more complex. I can leave you here one approach that you can 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