Skip to content

Commit b74a05c

Browse files
committed
Added Capitalize to coding challenges.
1 parent 6d150e9 commit b74a05c

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

capitalize/capitalize.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/***************************************************************
2+
* *
3+
* CodePrep.io *
4+
* *
5+
* Function: capitalize(str) *
6+
* Input: 1 string parameter *
7+
* Output: string *
8+
* *
9+
* Output expectations: *
10+
* var myTest = capitalize('hello world'); *
11+
* console.log(myTest); *
12+
* // Hello World *
13+
* *
14+
* Write the code for the capitalize function that *
15+
* capitalizes the first letter of each word in the *
16+
* string. If there are multiple words they will be *
17+
* separated by a single space. *
18+
* *
19+
**************************************************************/
20+
21+
var capitalize = function(str) {
22+
/* YOUR CODE GOES HERE */
23+
24+
};

capitalize/capitalize.test.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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('capitalize', function() {
9+
it('should exist', function(){
10+
should.exist(capitalize);
11+
});
12+
13+
it('should be a function', function() {
14+
capitalize.should.be.a.Function;
15+
});
16+
17+
it('should return an string', function() {
18+
var result = capitalize('hello');
19+
should.exist(result);
20+
result.should.be.an.instanceof(String);
21+
});
22+
23+
it('should return an empty string if no input provided', function() {
24+
var result = capitalize();
25+
result.should.be.eql('');
26+
});
27+
28+
it('should capitalize a single character', function(){
29+
var result = capitalize('a');
30+
result.should.be.eql('A');
31+
});
32+
33+
it('should capitalize the first letter of multiple worlds', function(){
34+
var result = capitalize('hello world');
35+
result.should.be.eql('Hello World');
36+
});
37+
38+
it('should not change capitalization for any other character', function(){
39+
var result = capitalize('hELLO wORLD');
40+
result.should.be.eql('HELLO WORLD');
41+
});
42+
43+
});

capitalize/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+
}

0 commit comments

Comments
 (0)