Skip to content

Commit 8e6a185

Browse files
committed
adding is palindrome test
1 parent 7a7dbb9 commit 8e6a185

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

project/js/functionality/isPalindrome.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
* @returns {boolean}
66
*/
77
function isPalindrome(word) {
8-
return word.toString() == reverseString(word.toString());
8+
return !word ? "" : word.toString() == word.toString().split("").reverse().join("");
99
}
1010
module.exports = isPalindrome;

tests/isPalindrome.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const isPalindrome = require("../project/js/functionality/isPalindrome.js");
2+
3+
it("always returns a boolean value", function () {
4+
expect(typeof isPalindrome("123")).toBe("boolean");
5+
});
6+
7+
it("returns true if word is palindrome", function () {
8+
expect(isPalindrome("mum")).toBe(true);
9+
});
10+
11+
it("returns false if word is not palindrome", function () {
12+
expect(isPalindrome("muom")).toBe(false);
13+
});
14+
15+
it("returns true if word is palindrome also if the parameter is number", function () {
16+
expect(isPalindrome(121)).toBe(true);
17+
});
18+
19+
it("returns false if word is not palindrome also if the parameter is number", function () {
20+
expect(isPalindrome(123)).toBe(false);
21+
});
22+
23+
it("returns empty string if there is no parameter", function () {
24+
expect(isPalindrome()).toBe("");
25+
});

0 commit comments

Comments
 (0)