File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -45,4 +45,17 @@ const PalindromeIterative = (string) => {
4545 return true
4646}
4747
48- export { PalindromeIterative , PalindromeRecursive }
48+ /**
49+ *
50+ * Checks if a string is a palindrome.
51+ * @author dev-madhurendra
52+ * @param {string } str - The string to check.
53+ * @returns {boolean } True if the string is a palindrome, false otherwise.
54+ *
55+ * @example
56+ * const isPalindrome = checkPalindrome('racecar'); // Returns true
57+ * const isNotPalindrome = checkPalindrome('hello'); // Returns false
58+ */
59+ const checkPalindrome = ( str ) => str . replace ( / \s / g, '' ) === str . replace ( / \s / g, '' ) . split ( '' ) . reverse ( ) . join ( '' )
60+
61+ export { PalindromeIterative , PalindromeRecursive , checkPalindrome }
Original file line number Diff line number Diff line change 1- import { PalindromeRecursive , PalindromeIterative } from '../Palindrome'
1+ import { PalindromeRecursive , PalindromeIterative , checkPalindrome } from '../Palindrome'
22
33describe ( 'Palindrome' , ( ) => {
44 it ( 'should return true for a palindrome for PalindromeRecursive' , ( ) => {
@@ -13,4 +13,13 @@ describe('Palindrome', () => {
1313 it ( 'should return true for a non-palindrome for PalindromeIterative' , ( ) => {
1414 expect ( PalindromeIterative ( 'JavaScript' ) ) . toBeFalsy ( )
1515 } )
16+
17+ it . each ( [
18+ [ 'radar' , true ] ,
19+ [ 'hello' , false ] ,
20+ [ 'r' , true ] ,
21+ [ ' racecar ' , true ]
22+ ] ) ( 'should return value is palindrome or not' , ( value , expected ) => {
23+ expect ( checkPalindrome ( value ) ) . toBe ( expected )
24+ } )
1625} )
You can’t perform that action at this time.
0 commit comments