added an algo for checking the string i palindrome or not (#1366)

Co-authored-by: madhuredra <madhuredra.tiwari@zemosolabs.com>
This commit is contained in:
Madhurendra Nath Tiwari
2023-09-23 21:30:10 +05:30
committed by GitHub
parent f5188ddf16
commit 6362cc967a
2 changed files with 24 additions and 2 deletions

View File

@ -45,4 +45,17 @@ const PalindromeIterative = (string) => {
return true
}
export { PalindromeIterative, PalindromeRecursive }
/**
*
* Checks if a string is a palindrome.
* @author dev-madhurendra
* @param {string} str - The string to check.
* @returns {boolean} True if the string is a palindrome, false otherwise.
*
* @example
* const isPalindrome = checkPalindrome('racecar'); // Returns true
* const isNotPalindrome = checkPalindrome('hello'); // Returns false
*/
const checkPalindrome = (str) => str.replace(/\s/g, '') === str.replace(/\s/g, '').split('').reverse().join('')
export { PalindromeIterative, PalindromeRecursive, checkPalindrome }