How to reverse a word and check if it is a palindrome and if an empty string is passed in javascript.
here is what i came up with but not working as desired.
function reverseString(str) {
return str.split("").reverse().join("");
}
am suppose to run it against a test, here is the test.
describe("Produce the reverse order of a word: ", function () {
describe("Case for en empty string", function() {
it("should return null for empty string", function() {
expect(reverseString('')).toEqual(null);
});
});
describe("Case for palindromes", function() {
it("should return true for `anna`", function() {
expect(reverseString('anna')).toEqual(true);
});
it("should return true for `NaN`", function() {
expect(reverseString('NaN')).toEqual(true);
});
it("should return true for `civic`", function() {
expect(reverseString('civic')).toEqual(true);
});
});
describe("Case for normal words", function() {
it("should return `skoob` for `books`", function() {
expect(reverseString('books')).toEqual('skoob');
});
it("should return `nomolos` for `solomon`", function() {
expect(reverseString('solomon')).toEqual('nomolos');
});
it("should return `csim` for `misc`", function() {
expect(reverseString('misc')).toEqual('csim');
});
});
});