/
9_IsPalindrome.js
44 lines (31 loc) · 899 Bytes
/
9_IsPalindrome.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const assert = require('assert');
/**
* @param {number} x
* @return {boolean}
*/
var isPalindrome = function(x) {
if (x == undefined || x.length == 0)
{
return false;
}
let original_string = x.toString();
// Take the string and flip it. If its the same, then
// its a palindrome:
let splitString = original_string.split("");
let reverseArray = splitString.reverse();
let reverse_string = reverseArray.join("");
return (original_string === reverse_string);
};
describe('9_IsPalindrome.js', function ()
{
it('should return true', function ()
{
let results = isPalindrome(12221);
assert.deepEqual(true, results);
});
it('should return false', function ()
{
let results = isPalindrome(123123123123);
assert.deepEqual(false, results);
});
});