This project was created using the Webstorm Node boilerplate, but you should be able to get it up and running in pretty much any code editor. I used Node v10.15.3. The only dependency for this project is Jasmine, which is what I used for the unit testing. Here is a step-by-step to get up and running to test this project.
To get started with Jasmine, taken from (https://jasmine.github.io/pages/getting_started.html):
-
Add Jasmine to your package.json:
npm install --save-dev jasmine
-
Initialize Jasmine in your project:
node node_modules/jasmine/bin/jasmine init
-
Set jasmine as your test script in your package.json (If you copied the package.json file from the gist you should be ok):
"scripts": { "test": "jasmine" }
-
To get Jasmine up and running quickly I ran the following command, this should give you the spec directory:
jasmine examples
-
I renamed the playerSpec.js file to testSpec.js.
-
Deleted everything in that file and replace with the contents from the
testSpec.js
file from the gist. -
If you don't already have an
index.js
file in your project, create it. -
Once you have an
index.js
file, copy and paste the contents of the index.js file from the gist into yourindex.js
file. -
To run the index.js file from the command line, make sure you are in the root directory and run
node index.js
-
If you need to debug the output, you can replace the
return
statement withconsole.log([].concat.apply([],tempArray));
-
To run the unit test from the command line, use
npm test
. -
If you have any trouble with installing and testing this gist, please email [email protected]
Directory Structure should look something like this:
.
├── node_modules // Node Modules library root
├── spec // Jasmine Config
│ ├── jasmine_examples // Directory that contains testSpec.js
│ ├── testSpec.js // This is the unit test file (required for tests)
│ ├── support // Directory that contains default Jasmine config
│ ├── jasmine.json // This is the default Jasmine config (required)
├── index.js // Contains the flatten array function (required)
├── package.json
├── package-lock.json // npm lock file
├── README.md // this file