Skip to content
Open
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
18 changes: 18 additions & 0 deletions javascript/Utility/isStringPalindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function isStringPalindrome(str) {

// find the length of a string
const len = str.length;

// loop through half of the string
for (let i = 0; i < len / 2; i++) {
// check if first and last string are not same
if (str[i] !== str[len - 1 - i]) {
return 'It is not a palindrome';
}
}

return 'It is a palindrome';
}

// isStringPalindrome("REVIVER") result: It is a palindrome
// isStringPalindrome("ABCD") result: It is not a palindrome