diff --git a/lab-nathan/.eslintignore b/lab-nathan/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/lab-nathan/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/lab-nathan/.eslintrc b/lab-nathan/.eslintrc new file mode 100644 index 0000000..c8dfef7 --- /dev/null +++ b/lab-nathan/.eslintrc @@ -0,0 +1,23 @@ +{ + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": [ "error", "single" ], + "semi": ["error", "always"], + "linebreak-style": [ "error", "unix" ] + }, + "env": { + "es6": true, + "node": true, + "mocha": true, + "jasmine": true + }, + "parserOptions": { + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + } + }, + "extends": "eslint:recommended" +} diff --git a/lab-nathan/.gitignore b/lab-nathan/.gitignore new file mode 100644 index 0000000..345130c --- /dev/null +++ b/lab-nathan/.gitignore @@ -0,0 +1,136 @@ +# Created by https://www.gitignore.io/api/osx,vim,node,macos,windows + +### macOS ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### OSX ### + +# Icon must end with two \r + +# Thumbnails + +# Files that might appear in the root of a volume + +# Directories potentially created on remote AFP share + +### Vim ### +# swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-v][a-z] +[._]sw[a-p] +# session +Session.vim +# temporary +.netrwhist +*~ +# auto-generated tag files +tags + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/osx,vim,node,macos,windows diff --git a/lab-nathan/index.js b/lab-nathan/index.js new file mode 100644 index 0000000..5fced61 --- /dev/null +++ b/lab-nathan/index.js @@ -0,0 +1,5 @@ +'use strict'; + +const fp = require('./lib/fp.js'); + +fp.map(process.argv.slice(2), a => console.log(a.toUpperCase())); \ No newline at end of file diff --git a/lab-nathan/lib/fp.js b/lab-nathan/lib/fp.js new file mode 100644 index 0000000..09cbe80 --- /dev/null +++ b/lab-nathan/lib/fp.js @@ -0,0 +1,13 @@ +'use strict'; + +let fp = {}; +module.exports = fp; + +fp.map = (array, func) => Array.prototype.map.call(array, func); +fp.filter = (array, predicate) => Array.prototype.filter.call(array, predicate); +fp.reduce = (array, func, initialValue) => Array.prototype.reduce.call(array, func, initialValue); +fp.concat = (arrayA, arrayB) => Array.prototype.concat.call(arrayA, arrayB); +fp.splice = (array, start, deleteCount, items) => { + Array.prototype.splice.call(array, start, deleteCount, ...items); + return array; +}; \ No newline at end of file diff --git a/lab-nathan/package.json b/lab-nathan/package.json new file mode 100644 index 0000000..fd82602 --- /dev/null +++ b/lab-nathan/package.json @@ -0,0 +1,18 @@ +{ + "name": "lab-nathan", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "node index.js", + "lint": "eslint .", + "test": "mocha" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "chai": "^4.1.0", + "mocha": "^3.4.2" + } +} diff --git a/lab-nathan/test/fp-test.js b/lab-nathan/test/fp-test.js new file mode 100644 index 0000000..53f9e11 --- /dev/null +++ b/lab-nathan/test/fp-test.js @@ -0,0 +1,61 @@ +'use strict'; + +const fp = require('../lib/fp.js'); +const expect = require('chai').expect; + +describe('fp', () => { + describe('#map()', () => { + it('should fail with invalid inputs.', () => { + expect(fp.map).to.throw(Error); + }); + + it('should return an array of doubled values.', () => { + let result = fp.map([1, 2, 3], num => num * 2); + expect(result).to.deep.equal([2, 4, 6]); + }); + }); + + describe('#filter()', () => { + it('should fail with invalid inputs.', () => { + expect(fp.filter).to.throw(Error); + }); + + it('should return 2.', () => { + let result = fp.filter([1, 2, 3], num => num !== 2); + expect(result).to.deep.equal([1, 3]); + }); + }); + + describe('#reduce()', () => { + it('should fail with invalid inputs.', () => { + expect(fp.reduce).to.throw(Error); + }); + + it('should return 6.', () => { + let result = fp.reduce([1, 2, 3], (acc, cur) => acc + cur, 0); + expect(result).to.equal(6); + }); + }); + + describe('#concat()', () => { + it('should fail with invalid inputs.', () => { + expect(fp.concat).to.throw(Error); + }); + + it('should return [1, 2, 3, 4, 5, 6].', () => { + let result = fp.concat([1, 2, 3], [4, 5, 6]); + expect(result).to.deep.equal([1, 2, 3, 4, 5, 6]); + }); + }); + + describe('#splice()', () => { + it('should fail with invalid inputs.', () => { + expect(fp.splice).to.throw(Error); + }); + + it('should return [1, 2, 3, 7, 8, 9, 4, 5, 6].', () => { + let result = fp.splice([1, 2, 3, 4, 5, 6], 3, 0, [7, 8, 9]); + expect(result).to.deep.equal([1, 2, 3, 7, 8, 9, 4, 5, 6]); + }); + }); +}); \ No newline at end of file diff --git a/lab-nathan/test/index-test.js b/lab-nathan/test/index-test.js new file mode 100644 index 0000000..5c97298 --- /dev/null +++ b/lab-nathan/test/index-test.js @@ -0,0 +1,23 @@ +'use strict'; + +const expect = require('chai').expect; +const { spawn } = require('child_process'); + +describe('index', () => { + it('should produce uppercase params.', done => { + let child = spawn('node', ['index.js', 'hi', 'hello'], { + shell: true, + }); + + let buffer = []; + + child.stdout.on('data', chunk => { + buffer.push(chunk.toString().trim()); + }); + + child.stdout.on('end', () => { + expect(buffer.join(' ')).to.equal('HI HELLO'); + done(); + }); + }); +}); \ No newline at end of file