diff --git a/src/helpers/index.ts b/src/helpers/index.ts index d377da46..4b0594aa 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -1,2 +1,3 @@ export { divisors } from './divisors'; export { isPrime } from './prime'; +export { isPalindrome } from './isPalindrome'; diff --git a/src/helpers/isPalindrome.test.ts b/src/helpers/isPalindrome.test.ts new file mode 100644 index 00000000..d2a366a6 --- /dev/null +++ b/src/helpers/isPalindrome.test.ts @@ -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); + }); +}); diff --git a/src/helpers/isPalindrome.ts b/src/helpers/isPalindrome.ts new file mode 100644 index 00000000..b4e5be6d --- /dev/null +++ b/src/helpers/isPalindrome.ts @@ -0,0 +1,4 @@ +export const isPalindrome = (n: number): boolean => + n.toString().split('').reverse().join('') === n.toString(); + +export default { isPalindrome };