Skip to content

Commit

Permalink
New helper: isPalindrome. Check if the number complies with the prope…
Browse files Browse the repository at this point in the history
…rty of being written equally from left to right as from right to left.
  • Loading branch information
sir-gon committed May 18, 2023
1 parent ed4af32 commit aa24660
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/helpers/index.ts
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';
12 changes: 12 additions & 0 deletions src/helpers/isPalindrome.test.ts
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);
});
});
4 changes: 4 additions & 0 deletions src/helpers/isPalindrome.ts
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 };

0 comments on commit aa24660

Please sign in to comment.