From d168bae76764f4924841690ff7f26e071db19b0e Mon Sep 17 00:00:00 2001 From: Bret Ldenburg Date: Tue, 18 Jul 2017 16:14:21 -0700 Subject: [PATCH 1/2] finished with lab 2 today --- .eslintignore | 5 ++ .eslintrc | 21 ++++++++ .gitignore | 136 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/fp.js | 30 +++++++++++ package.json | 29 +++++++++++ test/fptest.js | 97 +++++++++++++++++++++++++++++++++++ 6 files changed, 318 insertions(+) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 lib/fp.js create mode 100644 package.json create mode 100644 test/fptest.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,21 @@ +{ + "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 + }, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..345130c --- /dev/null +++ b/.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/lib/fp.js b/lib/fp.js new file mode 100644 index 0000000..255d52d --- /dev/null +++ b/lib/fp.js @@ -0,0 +1,30 @@ +'use strict'; + +module.exports = exports = {}; + +exports.map = (arr, callback) => { + if(!arr) throw new Error('array not provided'); + return Array.prototype.map.call(arr, callback); +}; + +exports.filter = (arr, callback) => { + if(!arr) throw new Error('array not provided'); + return Array.prototype.map.call(arr, callback); +}; + +exports.concat = (arr1, arr2) => { + if(!arr1) throw new Error('initial array not provided'); + return Array.prototype.concat.apply(arr1, arr2); +}; + +exports.reduce = (arr, callback, init) => { + if(!arr) throw new Error('array not provided'); + if(init !== undefined) return Array.prototype.reduce.call(arr, callback); + return Array.prototype.reduce.call(arr, callback, init); +}; + +exports.splice = (arr, start, deleteCount, insertion) => { + if(!arr) throw new Error('initial array not provided'); + Array.prototype.splice.call(arr, start, deleteCount, insertion); + return arr; +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..de6ba87 --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "02-tools_and_context", + "version": "1.0.0", + "description": "![cf](https://i.imgur.com/7v5ASc8.png) 02: Tools and Context ======", + "main": "index.js", + "directories": { + "test": "test" + }, + "scripts": { + "start": "npm run index.js", + "test": "mocha", + "lint": ".eslintrc" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/bretladenburg/02-tools_and_context.git" + }, + "keywords": [], + "author": "", + "license": "MIT", + "bugs": { + "url": "https://github.com/bretladenburg/02-tools_and_context/issues" + }, + "homepage": "https://github.com/bretladenburg/02-tools_and_context#readme", + "devDependencies": { + "chai": "^4.1.0", + "mocha": "^3.4.2" + } +} diff --git a/test/fptest.js b/test/fptest.js new file mode 100644 index 0000000..5ebfbb2 --- /dev/null +++ b/test/fptest.js @@ -0,0 +1,97 @@ +'use strict'; + +const expect = require('chai').expect; +const fp = require('../lib/fp.js'); + +describe('fp Module', () => { + describe('#map',() => { + it('should return an array', () => { + expect(fp).to.have.property('map'); + expect(fp.map).to.be.a('function'); + }); + }); + + it('should throw a missing array error', () => { + var results = fp.map; + expect(results).to.throw(Error); + }); + + it('should return an array with tripled numbers', () => { + var results = fp.map([1,2,3], (n) => { + return n * 3; + }); + expect(results).to.be.an('array').that.includes.members([3,6,9]); + }); + + describe('#filter', () => { + it('should return an array', () => { + expect(fp).to.have.property('filter'); + expect(fp.filter).to.be.a('function'); + }); + }); + + it('should throw a missing array error', () => { + var results = fp.filter; + expect(results).to.throw(Error); + }); + + it('should return an array without the number 3', () => { + var results = fp.filter([1,2,3,4], (a) => { + return a !== 3; + }); + expect(results).to.be.an('array').to.not.have.members([3]); + }); + + describe('#reduce', () => { + it('should return a function', () => { + expect(fp).to.have.property('reduce'); + expect(fp.reduce).to.be.a('function'); + }); + }); + + it('should throw a missing array error', () => { + var results = fp.reduce; + expect(results).to.throw(Error); + }); + + it('should return an array with all the elements in the array reduced to a single value', () => { + var results = fp.reduce([1,2,3,4], (acc, n) => { + return acc + n; + },0); + expect(results).to.be.a('number').that.equals(10); + }); + + describe('#concat', () => { + it('should return a function', () => { + expect(fp).to.have.property('concat'); + expect(fp.concat).to.be.an('function'); + }); + }); + + it('should throw a missing array error', () => { + var results = fp.concat; + expect(results).to.throw(Error); + }); + + it('should return an array combinding arr1 and arr2', () => { + var results = fp.concat([1,2,3],[4,5,6]); + expect(results).to.be.an('array').that.includes.members([1,2,3,4,5,6]); + }); + + describe('#splice', () => { + it('should return an function', () => { + expect(fp).to.have.property('splice'); + expect(fp.splice).to.be.an('function'); + }); + }); + + it('should throw a missing array error', () => { + var results = fp.splice; + expect(results).to.throw(Error); + }); + + it('should modify an array by adding or removing items', () => { + var results = fp.splice([1,2,3,4], 4, 0, 5); + expect(results).to.be.an('array').that.includes.members([1,2,3,4,5]); + }); +}); From dbbdcc301a36e78b42dac6196465ab8d06e681aa Mon Sep 17 00:00:00 2001 From: Bret Ldenburg Date: Wed, 19 Jul 2017 16:39:55 -0700 Subject: [PATCH 2/2] fixed the lint script in the package.JSON file --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index de6ba87..11c13f6 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "start": "npm run index.js", "test": "mocha", - "lint": ".eslintrc" + "lint": "eslint ." }, "repository": { "type": "git",