Skip to content

Commit 3750713

Browse files
committed
Added fizzBuzz to coding challenges
1 parent c0e6b00 commit 3750713

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

fizzBuzz/fizzBuzz.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/***************************************************************
2+
* *
3+
* CodePrep.io *
4+
* *
5+
* Function: fizzBuzz(num) *
6+
* Input: 1 number parameter *
7+
* Output: array *
8+
* *
9+
* Output expectations: *
10+
* var myTest = fizzBuss(10); *
11+
* console.log(myTest); *
12+
* // [1, 2, fizz, 4, buzz, fizz, 7, 8, fizz, buzz] *
13+
* *
14+
* Write the code for the fizzBuzz function that *
15+
* accepts a number input and then loops from 1 to num *
16+
* and adding the number to an array unless it meets *
17+
* any of the requirements below. *
18+
* It will output the number unless it is a multiple of *
19+
* 3, 5 or 15. If the number is a multiple of 3 the *
20+
* output should be 'fizz'. If the number is a multiple *
21+
* of 5 it should output 'buzz'. If the number is a *
22+
* multiple of 15 it should output 'fizzbuzz' *
23+
* *
24+
**************************************************************/
25+
26+
var fizzBuzz = function(num) {
27+
/* YOUR CODE GOES HERE */
28+
29+
};

fizzBuzz/fizzBuzz.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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('fizzBuzz', function() {
9+
it('should exist', function(){
10+
should.exist(fizzBuzz);
11+
});
12+
13+
it('should be a function', function() {
14+
fizzBuzz.should.be.a.Function;
15+
});
16+
17+
it('should return an Array', function() {
18+
var result = fizzBuzz(5);
19+
should.exist(result);
20+
result.should.be.an.instanceof(Array);
21+
});
22+
23+
it('should return an empty array if no input provided', function() {
24+
var result = fizzBuzz();
25+
result.should.be.eql([]);
26+
});
27+
28+
it('should return an array with a single value if input is 1', function(){
29+
var result = fizzBuzz(1);
30+
result.should.be.eql([1]);
31+
});
32+
33+
it('should have the right number of entries in the Array', function(){
34+
var result = fizzBuzz(5);
35+
var len = result.length;
36+
len.should.be.eql(5);
37+
});
38+
39+
it('should have the right values', function() {
40+
var expected = [1,2,'fizz',4,'buzz','fizz',7,8,'fizz','buzz',11,'fizz',13,14,'fizzbuzz'];
41+
var result = fizzBuzz(15);
42+
result.should.be.eql(expected);
43+
});
44+
45+
it('should not have any special values if input is 2', function() {
46+
var expected = [1,2];
47+
var result = fizzBuzz(2);
48+
result.should.be.eql(expected);
49+
});
50+
51+
});

fizzBuzz/package.json

Lines changed: 10 additions & 0 deletions
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)