Skip to content

Commit c47b958

Browse files
committed
Added palindrome to coding challenges
1 parent 711c421 commit c47b958

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

palindrome/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "CodePrep.io_coding_challenges",
3+
"author": "Jennifer Bland",
4+
"url": "http://www.codeprep.io",
5+
"version": "1.0.0",
6+
"description": "CodePrep.io presents coding challenges you might face when interviewing for a Full-Stack Developer position",
7+
"scripts": {
8+
"test": "node ../node_modules/mocha/bin/mocha ./*.test.js"
9+
}
10+
}

palindrome/palindrome.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/***************************************************************
2+
* *
3+
* CodePrep.io *
4+
* *
5+
* Function: palindrome(str) *
6+
* Input: 1 string parameter *
7+
* Output: boolean *
8+
* *
9+
* Output expectations: *
10+
* var myTest = palindrome('civic'); *
11+
* console.log(myTest); // true *
12+
* *
13+
* A palindrome is a word, phrase or number which *
14+
* reads the same backward or forward. *
15+
* *
16+
* Write the code for the palindrome function that *
17+
* accepts a string input and then returns true or *
18+
* false if that string is a palindrome. Allowances *
19+
* must be made for capital letters, punctuation and *
20+
* word dividers. *
21+
* *
22+
**************************************************************/
23+
24+
var palindrome = function(str) {
25+
/* YOUR CODE GOES HERE */
26+
27+
};

palindrome/palindrome.test.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var should = require('should');
2+
var vm = require('vm');
3+
var fs = require('fs');
4+
var filename = __filename.replace(/\.test\.js$/, '.js');
5+
vm.runInThisContext(fs.readFileSync(filename), filename);
6+
7+
8+
describe('palindrome', function() {
9+
it('should exist', function(){
10+
should.exist(palindrome);
11+
});
12+
13+
it('should be a function', function() {
14+
palindrome.should.be.a.Function;
15+
});
16+
17+
it('should return a boolean', function() {
18+
var result = palindrome('hello');
19+
should.exist(result);
20+
result.should.be.an.instanceof(Boolean);
21+
});
22+
23+
it('should return false if no input provided', function() {
24+
var result = palindrome();
25+
result.should.be.eql(false);
26+
});
27+
28+
it('should return true for a single character', function(){
29+
var result = palindrome('a');
30+
result.should.be.eql(true);
31+
});
32+
33+
it('should remove spaces and punctuation to create palindrome', function(){
34+
var result = palindrome('able was I! ere I saw elba');
35+
result.should.be.eql(true);
36+
});
37+
38+
it('should work with input string of numbers', function() {
39+
var result = palindrome('707');
40+
result.should.be.eql(true);
41+
});
42+
43+
it('should not let case of characters impact creation of palindrome', function(){
44+
var result = palindrome('RaceCAr');
45+
result.should.be.eql(true);
46+
});
47+
48+
});

0 commit comments

Comments
 (0)