Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit73d4c05

Browse files
committed
Fixed some of the code by refactoring it and then getting the correct function from the correct resource.
1 parentd211d5c commit73d4c05

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

‎palindrome.js‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
// Function Declaration
44
functionpalindrome(word){
5-
return[...word.toLowerCase()].reverse().join('')==word.toLowerCase() ?true :false
5+
return[...word.toLowerCase()].reverse().join('')==word.toLowerCase();
66
}
77
// Function Expression
88

9-
constpalindrome2=(word)=>[...word.toLowerCase()].reverse().join("")==word.toLowerCase() ?true :false
9+
constpalindrome2=(word)=>[...word.toLowerCase()].reverse().join("")==word.toLowerCase();
1010

1111
console.log(palindrome("RaceCar"))
12-
console.log('function palindrome(word){return [...word.toLowerCase()].reverse().join("") == word.toLowerCase() ? true : false}'.length)
12+
console.log('function palindrome(word){return [...word.toLowerCase()].reverse().join("") == word.toLowerCase();}'.length)
1313

1414
console.log(palindrome2("LeVel"))
15-
console.log('const palindrome2 = (word) => [...word.toLowerCase()].reverse().join("") == word.toLowerCase() ? true : false'.length)
15+
console.log('const palindrome2 = (word) => [...word.toLowerCase()].reverse().join("") == word.toLowerCase();'.length)
1616

1717

1818
// Free Code Camp Version of Palindrome Solution
19-
functionpalindrome(str){return[...str.toLowerCase().replace(/[_*-\\.,\\\\\\(\\)]/g, \"\")].reverse().join(\"\") == str.toLowerCase().replace(/[_*-\\.,\\\\\\(\\) ]/g,\"\") ? true : false;
19+
functionpalindrome(str){
20+
returnstr.replace(/[\W_]/g,'').toLowerCase()===
21+
str.replace(/[\W_]/g,'').toLowerCase().split('').reverse().join('');
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp