Skip to content

LIS-WDFT-APR23-TOMÁS-ROSHAN #25

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

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