Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fa5b8b7

Browse files
Palindrome 🐛
1 parent 8f41dfd commit fa5b8b7

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

‎examples/usecases/palindrome.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var Stack = require('../datastructures/stack');
2+
3+
function palindrome(word) {
4+
var s = new Stack();
5+
for(var i = 0; i < word.length; i++)
6+
s.push(word[i]);
7+
var newWord = "";
8+
while(!s.empty())
9+
newWord += s.pop();
10+
return newWord == word;
11+
}
12+
13+
module.exports = palindrome;

‎test/usecases/palindrome.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var expect = require('chai').expect;
2+
var palindrome = require('../../examples/usecases/palindrome');
3+
4+
describe('=> PALINDROME', function() {
5+
6+
it('should ensure `PANAMA` is not palindrome', function(done) {
7+
expect(palindrome("PANAMA")).to.equal(false);
8+
done();
9+
});
10+
11+
it('should ensure `DAD` is palindrome', function(done) {
12+
expect(palindrome("DAD")).to.equal(true);
13+
done();
14+
});
15+
16+
it('should ensure `RACECAR` is palindrome', function(done) {
17+
expect(palindrome("RACECAR")).to.equal(true);
18+
done();
19+
});
20+
21+
it('should ensure `RADAR` is palindrome', function(done) {
22+
expect(palindrome("RADAR")).to.equal(true);
23+
done();
24+
});
25+
26+
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /