-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New helper: isPalindrome. Check if the number complies with the prope…
…rty of being written equally from left to right as from right to left.
- Loading branch information
Showing
3 changed files
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { divisors } from './divisors'; | ||
export { isPrime } from './prime'; | ||
export { isPalindrome } from './isPalindrome'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { isPalindrome } from './isPalindrome'; | ||
|
||
describe('number is Palindrome', () => { | ||
it('some numbers are palindrome', () => { | ||
expect.assertions(4); | ||
|
||
expect(isPalindrome(1)).toBe(true); | ||
expect(isPalindrome(131)).toBe(true); | ||
expect(isPalindrome(1221)).toBe(true); | ||
expect(isPalindrome(123454321)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const isPalindrome = (n: number): boolean => | ||
n.toString().split('').reverse().join('') === n.toString(); | ||
|
||
export default { isPalindrome }; |