File tree 2 files changed +24
-2
lines changed
2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -45,4 +45,17 @@ const PalindromeIterative = (string) => {
45
45
return true
46
46
}
47
47
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'
2
2
3
3
describe ( 'Palindrome' , ( ) => {
4
4
it ( 'should return true for a palindrome for PalindromeRecursive' , ( ) => {
@@ -13,4 +13,13 @@ describe('Palindrome', () => {
13
13
it ( 'should return true for a non-palindrome for PalindromeIterative' , ( ) => {
14
14
expect ( PalindromeIterative ( 'JavaScript' ) ) . toBeFalsy ( )
15
15
} )
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
+ } )
16
25
} )
You can’t perform that action at this time.
0 commit comments