hint [2/9]
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]
hint [3/9]
You may use regular expressions (RegExp
) to remove unwanted characters from the string.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [4/9]
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]
hint [5/9]
You may lowercase the string using String.prototype.toLowerCase
.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [6/9]
Solution ahead!
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [7/9]
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]
hint [8/9]
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;
}
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]
hint [1/9]
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]
hint [1/9]
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]
hint [2/9]
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]
hint [1/9]
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]
hint [2/9]
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]
hint [3/9]
You may use regular expressions (RegExp
) to remove unwanted characters from the string.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [4/9]
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]
hint [5/9]
You may lowercase the string using String.prototype.toLowerCase
.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [6/9]
Solution ahead!
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [7/9]
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]
/[\W_]/g
hint [1/9]
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]
hint [1/9]
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]
hint [2/9]
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]
hint [3/9]
You may use regular expressions (RegExp
) to remove unwanted characters from the string.
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [4/9]
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]