Skip to content
Merged
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions String/CheckPalindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Palindrome check is case sensitive; i.e. Aba is not a palindrome
// input is a string
const checkPalindrome = (str) => {
// check that input is a string
if (typeof str !== 'string') {
return 'Not a string'
}
// Store the length of the input string in a variable
const length = str.length
if (length === 0) {
return 'Empty string'
}
// Iterate through the length of the string
// Compare the first character to the last, the second character to the second last, and so on
for (let i = 0; i < length / 2; i++) {
// at the first instance of a mismatch
if (str[i] !== str[length - 1 - i]) {
return 'Not a Palindrome'
}
}
return 'Palindrome'
}

console.log(checkPalindrome('madam'))
console.log(checkPalindrome('abcd'))
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
"license": "GPL-3.0",
"dependencies": {
"node-fetch": "2.6.0"
},
"devDependencies": {
"standard": "^14.3.4"
}
}
}