Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit90addf9

Browse files
committed
Code/README fixes for the "Palindrome Check".
1 parentea28788 commit90addf9

File tree

6 files changed

+48
-41
lines changed

6 files changed

+48
-41
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ a set of rules that precisely define a sequence of operations.
102102
*`A`[Combination Sum](src/algorithms/sets/combination-sum) - find all combinations that form specific sum
103103
***Strings**
104104
*`B`[Hamming Distance](src/algorithms/string/hamming-distance) - number of positions at which the symbols are different
105-
*`B`[Palindrome Check](src/algorithms/string/palindrome-check) -isthe string the same in reverse
105+
*`B`[Palindrome](src/algorithms/string/palindrome) -check ifthe string is the same in reverse
106106
*`A`[Levenshtein Distance](src/algorithms/string/levenshtein-distance) - minimum edit distance between two sequences
107107
*`A`[Knuth–Morris–Pratt Algorithm](src/algorithms/string/knuth-morris-pratt) (KMP Algorithm) - substring search (pattern matching)
108108
*`A`[Z Algorithm](src/algorithms/string/z-algorithm) - substring search (pattern matching)

‎src/algorithms/string/palindrome-check/README.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

‎src/algorithms/string/palindrome-check/__test__/palindromeCheck.test.js

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#Palindrome Check
2+
3+
A[Palindrome](https://en.wikipedia.org/wiki/Palindrome) is a string that reads the same forwards and backwards.
4+
This means that the second half of the string is the reverse of the
5+
first half.
6+
7+
##Examples
8+
9+
The following are palindromes (thus would return`TRUE`):
10+
11+
```
12+
- "a"
13+
- "pop" -> p + o + p
14+
- "deed" -> de + ed
15+
- "kayak" -> ka + y + ak
16+
- "racecar" -> rac + e + car
17+
```
18+
19+
The following are NOT palindromes (thus would return`FALSE`):
20+
21+
```
22+
- "rad"
23+
- "dodo"
24+
- "polo"
25+
```
26+
27+
##References
28+
29+
-[GeeksForGeeks - Check if a number is Palindrome](https://www.geeksforgeeks.org/check-if-a-number-is-palindrome/)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
importisPalindromefrom'../isPalindrome';
2+
3+
describe('palindromeCheck',()=>{
4+
it('should return whether or not the string is a palindrome',()=>{
5+
expect(isPalindrome('a')).toBe(true);
6+
expect(isPalindrome('pop')).toBe(true);
7+
expect(isPalindrome('deed')).toBe(true);
8+
expect(isPalindrome('kayak')).toBe(true);
9+
expect(isPalindrome('racecar')).toBe(true);
10+
11+
expect(isPalindrome('rad')).toBe(false);
12+
expect(isPalindrome('dodo')).toBe(false);
13+
expect(isPalindrome('polo')).toBe(false);
14+
});
15+
});

‎src/algorithms/string/palindrome-check/palindromeCheck.jsrenamed to‎src/algorithms/string/palindrome/isPalindrome.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
*@return {boolean}
44
*/
55

6-
exportdefaultfunctionpalindromeCheck(string){
6+
exportdefaultfunctionisPalindrome(string){
77
letleft=0;
88
letright=string.length-1;
9+
910
while(left<right){
1011
if(string[left]!==string[right]){
1112
returnfalse;
1213
}
1314
left+=1;
1415
right-=1;
1516
}
17+
1618
returntrue;
1719
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp