-
Notifications
You must be signed in to change notification settings - Fork 10
FizzBuzz-Redux__W5-A4 Hollis (final) #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hollislau
wants to merge
4
commits into
SEA-Design-Dev:master
Choose a base branch
from
hollislau:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eec7671
Initial commit: add existing FizzBuzz files form last assignment
hollislau e58fb88
Refactor fizzbuzz code into node modules
hollislau d3a3958
Restructure module files to address dependency issues
hollislau 00b0775
Add package.json file in preparation of publishing the module
hollislau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <your-module>` and use it like so: | ||
|
|
||
| ``` | ||
| var FizzBuzz = require('<your-module>'); | ||
|
|
||
| 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-<your initials>` 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
|
|
||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
|
|
||
| })(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <[email protected]>", | ||
| "license": "ISC", | ||
| "bugs": { | ||
| "url": "https://github.com/hollislau/fizzbuzz-redux__W5-A4/issues" | ||
| }, | ||
| "homepage": "https://github.com/hollislau/fizzbuzz-redux__W5-A4" | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than simply pushing your values in to your
_stringsArray, when your constructor is run you might want to also reset your_stringsArray; the current implementation actually keeps it from allowing different instances to have different output. Currently, this is what's happening:Basically, with these private variables, you're sharing your data between the instances (which can be useful in some cases). It might make more sense to store the
_stringsArrayas a property of the instance:this.stringsArrayinstead: