diff --git a/README.md b/README.md index 9ebcd00..548da92 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,3 @@ -# fizzbuzz-redux__W5-A4 - -Tonight's assignment: refactor your FizzBuzz into a library and publish it to the npm registry. - -You will first refactor the object to have an `input` and an `output` method, instead of the "read" and "write" methods. - -Just like last night's homework, your constructor should accept arguments that change the strings "Fizz" and "Buzz" (e.g. `new FizzBuzz('Bleep', 'Blorp')`). The `input` method should accept two arguments, `min` and `max`—you may safely assume they are `Numbers`. `output` does not take any arguments, but _must_ return an array. - -Your module should expose a function using the CommonJS `module.exports` construct. I should be able to `npm install ` and use it like so: - -``` -var FizzBuzz = require(''); - -var buzzer = new FizzBuzz(); // Should accept string arguments that replace 'Fizz' and 'Buzz' -buzzer.input(1, 120); - -console.log(buzzer.output()); -``` - -Name your module `sea-d44-fizz-buzz-` and publish it to the npm registry. And, as usual, fork this repo and submit a PR. - +# sea-d44-fizz-buzz-hl +A simple application that generates the classic FizzBuzz responses for a given set of numbers. The application can accept user provided start, end, and string values to customize the output. diff --git a/generator.js b/generator.js new file mode 100644 index 0000000..8bcb405 --- /dev/null +++ b/generator.js @@ -0,0 +1,30 @@ +"use strict"; + +(function() { + + function _generateOutput(min, max, strings) { + var string1 = strings[0] || "Fizz"; + var string2 = strings[1] || "Buzz"; + var outputArray = []; + + for(var i = min; i <= max; i++) { + var output = ""; + + if (i % 3 === 0) { + output = string1; + } + if (i % 5 === 0) { + output += string2; + } + if (!output) { + output = i; + } + outputArray.push(output); + } + + return outputArray; + } + + module.exports = _generateOutput; + +})(); diff --git a/index.js b/index.js new file mode 100644 index 0000000..5d1b76f --- /dev/null +++ b/index.js @@ -0,0 +1,25 @@ +"use strict"; + +(function() { + + var _generateOutput = require("./generator.js"); + + var _stringsArray = []; + var _outputArray; + + var FizzBuzz = function(string1, string2) { + _stringsArray.push(string1, string2); + } + + FizzBuzz.prototype = { + input: function(min, max) { + _outputArray = _generateOutput(min, max, _stringsArray); + }, + output: function() { + return _outputArray; + } + } + + module.exports = FizzBuzz; + +})(); diff --git a/package.json b/package.json new file mode 100644 index 0000000..c4d42d2 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "sea-d44-fizz-buzz-hl", + "version": "1.0.0", + "description": "A simple application that generates the classic FizzBuzz responses for a given set of numbers.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/hollislau/fizzbuzz-redux__W5-A4.git" + }, + "keywords": [ + "sea-d44" + ], + "author": "Hollis Lau ", + "license": "ISC", + "bugs": { + "url": "https://github.com/hollislau/fizzbuzz-redux__W5-A4/issues" + }, + "homepage": "https://github.com/hollislau/fizzbuzz-redux__W5-A4" +}