## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
CamperBot
@camperbot

hint [8/9]

## Second

function palindrome(str) {
str = str.toLowerCase().replace(/[\W_]/g, '');
for(var i = 0, len = str.length - 1; i < len/2; i++) {
if(str[i] !== str[len-i]) {
return false;
}
}
return true;
}

# Code Explanation:

We use regular expressions to replace any uppercase letter into a lowercase. Then we check if the string is the same as the reversed string using split() to split the original string by characters, then reverse and then join it back together.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

GangstaCoder
@GangstaCoder
Thx camperbot. hint 1 unlocks it
GangstaCoder
@GangstaCoder
why the square brackets and underscore?: [\W_]
GangstaCoder
@GangstaCoder
why not /\W/g ?
joelauerbach0
@joelauerbach0
hint
CamperBot
@camperbot

hint [1/9]

## ## :construction: After this are possible spoiler hints.

Make sure you've tried to hard to solve it yourself before proceeding. :construction:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

joelauerbach0
@joelauerbach0
hint
CamperBot
@camperbot

hint [2/9]

# Explanation:

You have to check if the string you get as an input is a palindrome and return true if it is, and false otherwise.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

joelauerbach0
@joelauerbach0
hint
CamperBot
@camperbot

hint [3/9]

## Hint: 1

You may use regular expressions (RegExp) to remove unwanted characters from the string.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

joelauerbach0
@joelauerbach0
hint
CamperBot
@camperbot

hint [4/9]

## Hint: 2

You may use Array.prototype.split and Array.prototype.join methods or for loop.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

joelauerbach0
@joelauerbach0
hint
CamperBot
@camperbot

hint [5/9]

## Hint: 3

You may lowercase the string using String.prototype.toLowerCase.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

joelauerbach0
@joelauerbach0
hint
CamperBot
@camperbot

hint [6/9]

type hint for next hint :pencil: [Contribute at the FCC Wiki]

joelauerbach0
@joelauerbach0
hint
CamperBot
@camperbot

hint [7/9]

## First

function palindrome(str) {
var normalizedStr = str.replace(/[\W_]/g, '').toLowerCase();
var reverseStr = normalizedStr.split('').reverse().join('');
return normalizedStr === reverseStr;
}

type hint for next hint :pencil: [Contribute at the FCC Wiki]

joelauerbach0
@joelauerbach0
hint
CamperBot
@camperbot

hint [8/9]

## Second

function palindrome(str) {
str = str.toLowerCase().replace(/[\W_]/g, '');
for(var i = 0, len = str.length - 1; i < len/2; i++) {
if(str[i] !== str[len-i]) {
return false;
}
}
return true;
}

# Code Explanation:

We use regular expressions to replace any uppercase letter into a lowercase. Then we check if the string is the same as the reversed string using split() to split the original string by characters, then reverse and then join it back together.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

onethreeeight
@onethreeeight
hint
CamperBot
@camperbot

hint [1/9]

## ## :construction: After this are possible spoiler hints.

Make sure you've tried to hard to solve it yourself before proceeding. :construction:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Oscar Gatamah
@gatamah
hint
CamperBot
@camperbot

hint [1/9]

## ## :construction: After this are possible spoiler hints.

Make sure you've tried to hard to solve it yourself before proceeding. :construction:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

CamperBot
@camperbot

hint [2/9]

# Explanation:

You have to check if the string you get as an input is a palindrome and return true if it is, and false otherwise.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

onethreeeight
@onethreeeight
hint
Roko Medančić
@R0k0
hint profile lookup
CamperBot
@camperbot

hint [1/9]

## ## :construction: After this are possible spoiler hints.

Make sure you've tried to hard to solve it yourself before proceeding. :construction:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Roko Medančić
@R0k0
hint
CamperBot
@camperbot

hint [2/9]

# Explanation:

You have to check if the string you get as an input is a palindrome and return true if it is, and false otherwise.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

codyWchamberlain
@codyWchamberlain
hint
CamperBot
@camperbot

hint [3/9]

## Hint: 1

You may use regular expressions (RegExp) to remove unwanted characters from the string.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

codyWchamberlain
@codyWchamberlain
hint
CamperBot
@camperbot

hint [4/9]

## Hint: 2

You may use Array.prototype.split and Array.prototype.join methods or for loop.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

codyWchamberlain
@codyWchamberlain
hint
CamperBot
@camperbot

hint [5/9]

## Hint: 3

You may lowercase the string using String.prototype.toLowerCase.

type hint for next hint :pencil: [Contribute at the FCC Wiki]

codyWchamberlain
@codyWchamberlain
hint
CamperBot
@camperbot

hint [6/9]

type hint for next hint :pencil: [Contribute at the FCC Wiki]

codyWchamberlain
@codyWchamberlain
hint
CamperBot
@camperbot

hint [7/9]

## First

function palindrome(str) {
var normalizedStr = str.replace(/[\W_]/g, '').toLowerCase();
var reverseStr = normalizedStr.split('').reverse().join('');
return normalizedStr === reverseStr;
}

type hint for next hint :pencil: [Contribute at the FCC Wiki]

karenkomine
@karenkomine
Can someone explain the stuff that is inside .replace in var normalizedStr?
karenkomine
@karenkomine
Why do we used ' ' ' /[\W_]/g ' ' ' ?
/[\W_]/g
In str.replace?
karenkomine
@karenkomine
How would you set up your code so that in a for loop, you check every single word in an array and you stop the for loop when you find the longest string in that array?
Ahmed Othman
@ahmedgothman
@karenkomine /[\W_]/g is for word characters similiar to [A-Za-z0-9]
@karenkomine sorry i thought it was a recent comment:D
Shruti Hardat
@shrutihardat
hint
CamperBot
@camperbot

hint [1/9]

## ## :construction: After this are possible spoiler hints.

Make sure you've tried to hard to solve it yourself before proceeding. :construction:

type hint for next hint :pencil: [Contribute at the FCC Wiki]

Shivang
@shivang207
hint Record Collection