Challenge: Palindrome Check
Welcome back to Day 2 of our 100 Days DSA Challenge! 🚀 Today’s challenge dives into the intriguing world of palindromes. Let’s explore the definition and various ways to determine if a given string is a palindrome.
The Challenge:
Write a function that checks if a given string is a palindrome. A palindrome is a sequence of characters that reads the same backward as forward, ignoring spaces, punctuation, and capitalization.
Examples:
- “racecar” is a palindrome.
- “civic” is a palindrome.
Challenge Yourself:
Take a moment to implement your solution before exploring ours. The beauty of coding lies in the various paths to a solution.
Solutions:
Solution 1 – Using In-Built Function:
const isPalindromeFn = (str) => {
return str === str.split('').reverse().join('');
}
This concise solution uses JavaScript’s in-built functions to reverse the string and checks if it remains unchanged. Quick, but let’s dig deeper.
Solution 2 – Without In-Built Function:
const isPalindrome = (str) => {
let revStr = ""
for(let i =str.length - 1; i >= 0;i--){
revStr+= str[i]
}
return revStr === str
}
This solution manually reverses the string and checks if it remains unchanged. A more comprehensive approach that delves into the intricacies of palindromes.
Conclusion:
Congratulations on conquering Day 2 of our DSA Challenge! Palindromes are a fascinating realm within coding. Stay tuned for tomorrow’s challenge, and keep the coding spirit alive!
Happy coding! 🌟💻
#100DaysDSAChallenge #DataStructures #Algorithms #ProgrammingCommunity #CodeNewbie #Palindrome