Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions String/Palindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Wikipedia: https://en.wikipedia.org/wiki/Palindrome

function isPalindrome (string) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this algo already exists #213

Copy link
Copy Markdown
Member Author

@ruppysuppy ruppysuppy Jun 30, 2020

Choose a reason for hiding this comment

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

Sorry, I didn't see it. I am closing the PR.

for (let i = 0; i < Math.floor(string.length / 2); i++) {
if (string[i] !== string[string.length - i - 1]) return false
}
return true
}

function main () {
// Result: true
console.log(isPalindrome('racecar'))
console.log(isPalindrome('wow'))
console.log(isPalindrome('delia saw i was ailed'))

// Result: false
console.log(isPalindrome('Hello'))
console.log(isPalindrome('Test'))
}

main()