From e4afab9bbb25c192ee1a498e4c41526fb3c3673e Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 12:25:20 -0700 Subject: [PATCH 01/15] added basic structure to folder --- .eslintignore | 5 ++ .eslintrc | 21 ++++++++ .gitignore | 136 ++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 0 lib/fp.js | 1 + package.json | 29 +++++++++++ test/test-fp.js | 1 + 7 files changed, 193 insertions(+) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 index.js create mode 100644 lib/fp.js create mode 100644 package.json create mode 100644 test/test-fp.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/index.js b/index.js new file mode 100644 index 0000000..e69de29 diff --git a/lib/fp.js b/lib/fp.js new file mode 100644 index 0000000..ad9a93a --- /dev/null +++ b/lib/fp.js @@ -0,0 +1 @@ +'use strict'; diff --git a/package.json b/package.json new file mode 100644 index 0000000..f3bb79d --- /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/codefellows-javascript-401d17/02-tools_and_context.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/codefellows-javascript-401d17/02-tools_and_context/issues" + }, + "homepage": "https://github.com/codefellows-javascript-401d17/02-tools_and_context#readme", + "devDependencies": { + "chai": "^4.1.0", + "mocha": "^3.4.2" + } +} diff --git a/test/test-fp.js b/test/test-fp.js new file mode 100644 index 0000000..ad9a93a --- /dev/null +++ b/test/test-fp.js @@ -0,0 +1 @@ +'use strict'; From 45690abf645d5eab274bc35270bbca746abe9eda Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 13:52:56 -0700 Subject: [PATCH 02/15] test is working for stand alone map --- lib/fp.js | 7 +++++++ test/test-fp.js | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/fp.js b/lib/fp.js index ad9a93a..bd7ea7b 100644 --- a/lib/fp.js +++ b/lib/fp.js @@ -1 +1,8 @@ 'use strict'; + +module.exports = exports = {}; + +exports.map = (arr, callback) => { + if (!arr) throw new Error('array not provided'); + return Array.prototype.map.call(arr, callback); +} diff --git a/test/test-fp.js b/test/test-fp.js index ad9a93a..a4b7633 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -1 +1,27 @@ 'use strict'; + +const fp = require('../lib/fp.js'); +const expect = require('chai').expect; + +describe('fp', () => { + describe('#map', () => { + it('should throw array not provided error', () => { + let mapArrErr = fp.map; + expect(mapArrErr).to.throw(Error); + }) + it('should return an array with doubled numbers', () => { + let validMap = fp.map([1,2,3,4], (n) => { return n * 2 }); + expect(validMap).to.be.an('array').that.includes.members([2,4,6,8]); + }) + }) + describe('#filter', () =>{ + it('should throw array not provided error', () => { + let filterArrErr = fp.map; + expect(filterArrErr).to.throw(Error); + }) + it('should return an array that is missing the number 2', () => { + let validFilter = filter([1, 2, 3, 4], function(n) { return n !== 2 }); + expect(validFilter) + }) + }) +}) From 0a167f48abbfd3093fe2e224d2555d133d035f45 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 14:04:31 -0700 Subject: [PATCH 03/15] filter is testing and working --- lib/fp.js | 5 +++++ test/test-fp.js | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/fp.js b/lib/fp.js index bd7ea7b..d0c45f8 100644 --- a/lib/fp.js +++ b/lib/fp.js @@ -5,4 +5,9 @@ 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.filter.call(arr, callback); } diff --git a/test/test-fp.js b/test/test-fp.js index a4b7633..0cc6d3d 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -16,12 +16,13 @@ describe('fp', () => { }) describe('#filter', () =>{ it('should throw array not provided error', () => { - let filterArrErr = fp.map; + let filterArrErr = fp.filter; expect(filterArrErr).to.throw(Error); }) it('should return an array that is missing the number 2', () => { - let validFilter = filter([1, 2, 3, 4], function(n) { return n !== 2 }); - expect(validFilter) + let validFilter = fp.filter([1, 2, 3, 4], (n) => { return n !== 2 }); + expect(validFilter).to.be.an('array').to.not.have.members([2]); }) }) + describe('#concat', () =>) }) From b6eb341a272a5d2fb86c6d8bf62f29d3d3efe24e Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 14:13:42 -0700 Subject: [PATCH 04/15] test work and validats concat --- lib/fp.js | 5 +++++ test/test-fp.js | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/fp.js b/lib/fp.js index d0c45f8..122e6a3 100644 --- a/lib/fp.js +++ b/lib/fp.js @@ -11,3 +11,8 @@ exports.filter = (arr, callback) => { if (!arr) throw new Error('array not provided'); return Array.prototype.filter.call(arr, callback); } + +exports.concat = (arr1, arr2) => { + if (!arr1) throw new Error('initial array not provided'); + return Array.prototype.concat.apply(arr1, arr2); +}; diff --git a/test/test-fp.js b/test/test-fp.js index 0cc6d3d..8546878 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -24,5 +24,14 @@ describe('fp', () => { expect(validFilter).to.be.an('array').to.not.have.members([2]); }) }) - describe('#concat', () =>) + describe('#concat', () => { + it('should throw an intial array not provided error', () => { + let concatArrErr = fp.concat; + expect(concatArrErr).to.throw(Error); + }) + it('should be an array the is a combination of two arrays', () => { + let validConcat = fp.concat([1,2,3], [4,5,6]); + expect(validConcat).to.be.an('array').to.include.members([1,2,3,4,5,6]) + }) + }) }) From 8ff41eab8ee7557a5ab39ceddce8158a4639afd7 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 15:57:00 -0700 Subject: [PATCH 05/15] reduce works and tests well --- lib/fp.js | 5 +++++ test/test-fp.js | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/fp.js b/lib/fp.js index 122e6a3..cf56d20 100644 --- a/lib/fp.js +++ b/lib/fp.js @@ -16,3 +16,8 @@ exports.concat = (arr1, arr2) => { if (!arr1) throw new Error('initial array not provided'); return Array.prototype.concat.apply(arr1, arr2); }; + +exports.reduce = (arr, idx, callback) => { + if (!arr) throw new Error('array not provided'); + return Array.prototype.reduce.call(arr, idx, callback); +}; diff --git a/test/test-fp.js b/test/test-fp.js index 8546878..4b88c90 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -34,4 +34,29 @@ describe('fp', () => { expect(validConcat).to.be.an('array').to.include.members([1,2,3,4,5,6]) }) }) + describe('#reduce', () =>{ + it('should throw an intial array not provided error', () => { + let reduceArrErr = fp.concat; + expect(reduceArrErr).to.throw(Error); + }) + it('should reduce an array down to a single value', () => { + let validReduce = fp.reduce([0, 1, 2, 3], (acc, n) => {return acc + n }, 0); + console.log(validReduce); + expect(validReduce).to.equal(6); + }) + it('should count amount of each name in an array and return it in an object', () => { + var names = ['Alice', 'Bob', 'Tiff', 'Bruce', 'Alice']; + var validNameReduce = fp.reduce(names, (allNames, name) => { + if (name in allNames) { + allNames[name]++; + } + else { + allNames[name] = 1; + } + return allNames; + }, {}); + console.log(validNameReduce); + expect(validNameReduce).to.be.an('object'); + }) + }) }) From 84f1bd2f06cb3d1e1f7c36ad6679ef732ba128c1 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 16:38:53 -0700 Subject: [PATCH 06/15] finished basic lab --- lib/fp.js | 8 +++++++- test/test-fp.js | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/fp.js b/lib/fp.js index cf56d20..0bd2cd2 100644 --- a/lib/fp.js +++ b/lib/fp.js @@ -10,7 +10,7 @@ exports.map = (arr, callback) => { exports.filter = (arr, callback) => { if (!arr) throw new Error('array not provided'); return Array.prototype.filter.call(arr, callback); -} +}; exports.concat = (arr1, arr2) => { if (!arr1) throw new Error('initial array not provided'); @@ -21,3 +21,9 @@ exports.reduce = (arr, idx, callback) => { if (!arr) throw new Error('array not provided'); return Array.prototype.reduce.call(arr, idx, callback); }; + +exports.splice = (arr, start, deletecount, insertion) => { + if (!arr) throw new Error('array not provided'); + Array.prototype.splice.call(arr, start, deletecount, insertion); + return arr; +}; diff --git a/test/test-fp.js b/test/test-fp.js index 4b88c90..1f6e09e 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -59,4 +59,14 @@ describe('fp', () => { expect(validNameReduce).to.be.an('object'); }) }) + describe('#splice', () => { + it('should throw an intial array not provided error', () =>{ + let spliceArrErr = fp.concat; + expect(spliceArrErr).to.throw(Error); + }) + it('should insert a value into a specific position in an array', () =>{ + let validsplice = fp.splice([1, 2, 3, 4, 5], 2, 0, 25); + expect(validsplice).to.be.an('array').to.include.members([1, 2, 25, 3, 4, 5]); + }) + }) }) From 9a34b287b36f3a9bcdcae37becd52301dfb299fc Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 17:39:57 -0700 Subject: [PATCH 07/15] toCaps work --- index.js | 14 ++++++++++++++ package.json | 2 +- test/test-fp.js | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e69de29..9db8ed4 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,14 @@ +'use strict'; + +const fp = require('../02-tools_and_context/lib/fp.js'); + + +var toCapsTerminal = () => { + let toCaps = fp.map(process.argv, (n) => { + return n.toUpperCase() + }); + toCaps.splice(0,2); + console.log(toCaps); +}; + +toCapsTerminal() diff --git a/package.json b/package.json index f3bb79d..783b95b 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "test" }, "scripts": { - "start": "npm run index.js", + "start": "node index.js", "test": "mocha", "lint": ".eslintrc" }, diff --git a/test/test-fp.js b/test/test-fp.js index 1f6e09e..23c90f4 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -1,6 +1,7 @@ 'use strict'; const fp = require('../lib/fp.js'); +const index = require('../index.js') const expect = require('chai').expect; describe('fp', () => { @@ -70,3 +71,7 @@ describe('fp', () => { }) }) }) + +describe('index', () => { + describe('#toCaps') +}) From c3cabf50f00d56426d3aee32bbac1693398c4f4f Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 18:50:01 -0700 Subject: [PATCH 08/15] got caps to work and a way to test it. time to write test --- index.js | 17 +++++++++++------ test/test-fp.js | 6 +++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 9db8ed4..c84f756 100644 --- a/index.js +++ b/index.js @@ -2,13 +2,18 @@ const fp = require('../02-tools_and_context/lib/fp.js'); - -var toCapsTerminal = () => { - let toCaps = fp.map(process.argv, (n) => { - return n.toUpperCase() +var toCapsTerminal = (word) => { + var words = word + var toCaps = fp.map(process.argv = 5, (val, index) => { + return val }); - toCaps.splice(0,2); + toCaps.splice(0, 2, words); + toCaps = fp.map(toCaps, (n) => { + toCaps = n.toUpperCase(); + console.log(toCaps); + return toCaps + }) console.log(toCaps); }; -toCapsTerminal() +toCapsTerminal('dog') diff --git a/test/test-fp.js b/test/test-fp.js index 23c90f4..9d2bc82 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -73,5 +73,9 @@ describe('fp', () => { }) describe('index', () => { - describe('#toCaps') + describe('#toCaps', () =>{ + it('should make all imput in command line capitalized', ()=>{ + let toCapsValid = + }) + }) }) From c43627619066aa750fb00515643803e54e80a94e Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 19:38:51 -0700 Subject: [PATCH 09/15] could not get the test to work --- index.js | 21 ++++++++------------- test/test-fp.js | 5 +++-- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index c84f756..0f0d630 100644 --- a/index.js +++ b/index.js @@ -1,19 +1,14 @@ 'use strict'; -const fp = require('../02-tools_and_context/lib/fp.js'); +const fp = require('/Users/jamesrbillard/programs/code_fellows/code_401/lab-james/02-tools_and_context/lib/fp.js'); -var toCapsTerminal = (word) => { - var words = word - var toCaps = fp.map(process.argv = 5, (val, index) => { - return val + +var toCapsTerminal = () => { + let toCaps = fp.map(process.argv, (n) => { + toCaps.splice(0,2); + return n.toUpperCase() }); - toCaps.splice(0, 2, words); - toCaps = fp.map(toCaps, (n) => { - toCaps = n.toUpperCase(); - console.log(toCaps); - return toCaps - }) - console.log(toCaps); + console.log(`this is just dog ${toCaps}`); }; -toCapsTerminal('dog') +toCapsTerminal() diff --git a/test/test-fp.js b/test/test-fp.js index 9d2bc82..aef1fee 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -74,8 +74,9 @@ describe('fp', () => { describe('index', () => { describe('#toCaps', () =>{ - it('should make all imput in command line capitalized', ()=>{ - let toCapsValid = + it('should make all imputs in command line capitalized', () => { + let toCapsValid = index.toCapsTerminal('dog'); + expect(toCapsValid).to.be.an('array'); }) }) }) From f8241eab4ead4d1282f5ae1683992196d8f4f120 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 20:30:04 -0700 Subject: [PATCH 10/15] finished whole assignment including stretch --- index.js | 20 ++++++++++---------- lib/fp.js | 16 +++++++++------- package.json | 1 + test/test-fp.js | 17 ++++------------- test/test-index.js | 26 ++++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 test/test-index.js diff --git a/index.js b/index.js index 0f0d630..2c639e4 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,14 @@ 'use strict'; -const fp = require('/Users/jamesrbillard/programs/code_fellows/code_401/lab-james/02-tools_and_context/lib/fp.js'); - - -var toCapsTerminal = () => { - let toCaps = fp.map(process.argv, (n) => { - toCaps.splice(0,2); - return n.toUpperCase() - }); - console.log(`this is just dog ${toCaps}`); +const fp = require('./lib/fp.js'); + +let main = module.exports = () => { + let list = fp.splice(process.argv, 2); + console.log(list); + list = fp.map(list, (word) => word.toUpperCase()); + let result = list.join(' '); + console.log(result); + return result; }; -toCapsTerminal() +main(); diff --git a/lib/fp.js b/lib/fp.js index 0bd2cd2..48207df 100644 --- a/lib/fp.js +++ b/lib/fp.js @@ -2,11 +2,13 @@ module.exports = exports = {}; -exports.map = (arr, callback) => { - if (!arr) throw new Error('array not provided'); - return Array.prototype.map.call(arr, callback); +exports.map = (list, ...args) => { + if (!list) throw new Error('array not provided'); + if (typeof list === 'object') + return Array.prototype.map.call(list, ...args); }; + exports.filter = (arr, callback) => { if (!arr) throw new Error('array not provided'); return Array.prototype.filter.call(arr, callback); @@ -22,8 +24,8 @@ exports.reduce = (arr, idx, callback) => { return Array.prototype.reduce.call(arr, idx, callback); }; -exports.splice = (arr, start, deletecount, insertion) => { - if (!arr) throw new Error('array not provided'); - Array.prototype.splice.call(arr, start, deletecount, insertion); - return arr; +exports.splice = (list, ...args) => { + if (!list) throw new Error('array not provided'); + if (typeof list === 'object') + return Array.prototype.splice.call(list, ...args); }; diff --git a/package.json b/package.json index 783b95b..420d320 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "homepage": "https://github.com/codefellows-javascript-401d17/02-tools_and_context#readme", "devDependencies": { "chai": "^4.1.0", + "expect": "^1.20.2", "mocha": "^3.4.2" } } diff --git a/test/test-fp.js b/test/test-fp.js index aef1fee..d6260b2 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -1,7 +1,6 @@ 'use strict'; const fp = require('../lib/fp.js'); -const index = require('../index.js') const expect = require('chai').expect; describe('fp', () => { @@ -65,18 +64,10 @@ describe('fp', () => { let spliceArrErr = fp.concat; expect(spliceArrErr).to.throw(Error); }) - it('should insert a value into a specific position in an array', () =>{ - let validsplice = fp.splice([1, 2, 3, 4, 5], 2, 0, 25); - expect(validsplice).to.be.an('array').to.include.members([1, 2, 25, 3, 4, 5]); - }) - }) -}) - -describe('index', () => { - describe('#toCaps', () =>{ - it('should make all imputs in command line capitalized', () => { - let toCapsValid = index.toCapsTerminal('dog'); - expect(toCapsValid).to.be.an('array'); + it('should return [6,7,8]', () => { + let result = fp.splice([1,2,3,4,5,6,7,8], 5); + console.log(result); + expect(result).to.be.an('array').to.include.members([6,7,8]) }) }) }) diff --git a/test/test-index.js b/test/test-index.js new file mode 100644 index 0000000..ca41778 --- /dev/null +++ b/test/test-index.js @@ -0,0 +1,26 @@ +'use strict'; + +const expect = require('expect'); +const main = require('../index.js'); + +describe('testing main', () => { + + var oldArgv = process.argv; + before(() => { + process.argv = [ + 'node path', + 'file path', + 'hello', + 'world', + ]; + }); + + after(() => { + process.argv = oldArgv; + }); + + it('should return \'HELLO WORLD\'', () => { + let result = main(); + expect(result).toBe('HELLO WORLD'); + }); +}); From 831bafb92221e6af7e806df682e1ad9e428aac4b Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 20:46:52 -0700 Subject: [PATCH 11/15] fixed small issues still need to fix naming conventions --- test/test-fp.js | 3 --- test/test-index.js | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/test/test-fp.js b/test/test-fp.js index d6260b2..97c1edb 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -41,7 +41,6 @@ describe('fp', () => { }) it('should reduce an array down to a single value', () => { let validReduce = fp.reduce([0, 1, 2, 3], (acc, n) => {return acc + n }, 0); - console.log(validReduce); expect(validReduce).to.equal(6); }) it('should count amount of each name in an array and return it in an object', () => { @@ -55,7 +54,6 @@ describe('fp', () => { } return allNames; }, {}); - console.log(validNameReduce); expect(validNameReduce).to.be.an('object'); }) }) @@ -66,7 +64,6 @@ describe('fp', () => { }) it('should return [6,7,8]', () => { let result = fp.splice([1,2,3,4,5,6,7,8], 5); - console.log(result); expect(result).to.be.an('array').to.include.members([6,7,8]) }) }) diff --git a/test/test-index.js b/test/test-index.js index ca41778..326123b 100644 --- a/test/test-index.js +++ b/test/test-index.js @@ -1,6 +1,6 @@ 'use strict'; -const expect = require('expect'); +const expect = require('chai').expect; const main = require('../index.js'); describe('testing main', () => { @@ -21,6 +21,6 @@ describe('testing main', () => { it('should return \'HELLO WORLD\'', () => { let result = main(); - expect(result).toBe('HELLO WORLD'); + expect(result).to.be.a('string').to.have.string('HELLO WORLD'); }); }); From f26cb7d233eb8db82ecc88e1831fbabfc0977a01 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 23:05:27 -0700 Subject: [PATCH 12/15] edited readme --- README.md | 38 +++++++------------------------------- index.js | 2 -- package.json | 2 +- test/test-index.js | 12 +++++------- 4 files changed, 13 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 67e3b00..c14f211 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,7 @@ -![cf](https://i.imgur.com/7v5ASc8.png) 02: Tools and Context -====== - -## To Submit this Assignment - * fork this repository & create a new branch for your work - * write all of your code in a directory named `lab-` + `` **e.g.** `lab-susan` - * push to your repository - * submit a pull request to this repository - * submit a link to your PR in canvas - * write a question and observation on canvas - -## Directions - * create a `/lib` and `/test` directory - * add a robust `.gitignore` file - * include a `package.json` - * include the provided `.eslintrc` file - * create a `lint` script for running eslint - * create a `test` script for running mocha - * create a `lib/fp.js` file for holding the following: - * create stand alone `map`, `filter`, `reduce`, `concat`, and `splice` functions using the `call`, and `apply` methods we discussed today - * you are welcome to use/experiment with `bind` too! - * *note:* - all functions should be created using the es6 lexical arrow function syntax - -# Tests - * create a test for each of your custom functions in `lib/fp.js` - * note - feel free to create additional tests, if you choose! - -## Bonus 2pts - * create a CLI (`index.js`) that will use your new `map` function to uppercase all command line arguments and print them to the screen: 1pt - * **hint:** - you'll want to check out the `process` object (and it's methods) to get an array of provided command line arguments - * test your CLI: 1pt +## Lab-James Lab-02 Documentation + * index.js calls function 'main' function which returns CLI parameters as uppercase words using the fp.splice method from ./lib/fp.js. + * ./lib/fp.js defines the map, filter, reduce, concat, and splice methods using both call and apply. + * Tests + * ./test/fp-test.js tests the above methods + * **Stretch Goal:** ./test/index-test.js tests the index.js CLI functionality. + * Project passes Mocha (chai) tests and esLint. diff --git a/index.js b/index.js index 2c639e4..43f3d10 100644 --- a/index.js +++ b/index.js @@ -4,10 +4,8 @@ const fp = require('./lib/fp.js'); let main = module.exports = () => { let list = fp.splice(process.argv, 2); - console.log(list); list = fp.map(list, (word) => word.toUpperCase()); let result = list.join(' '); - console.log(result); return result; }; diff --git a/package.json b/package.json index 420d320..acecf1f 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "start": "node index.js", "test": "mocha", - "lint": ".eslintrc" + "lint": ".eslint ." }, "repository": { "type": "git", diff --git a/test/test-index.js b/test/test-index.js index 326123b..a2e5881 100644 --- a/test/test-index.js +++ b/test/test-index.js @@ -3,15 +3,13 @@ const expect = require('chai').expect; const main = require('../index.js'); -describe('testing main', () => { - - var oldArgv = process.argv; +describe('main', () => {var oldArgv = process.argv; before(() => { process.argv = [ 'node path', 'file path', - 'hello', - 'world', + 'cat', + 'dog', ]; }); @@ -19,8 +17,8 @@ describe('testing main', () => { process.argv = oldArgv; }); - it('should return \'HELLO WORLD\'', () => { + it('should return \'CAT DOG\'', () => { let result = main(); - expect(result).to.be.a('string').to.have.string('HELLO WORLD'); + expect(result).to.be.a('string').to.have.string('CAT DOG'); }); }); From 0a7b881bdc3d8fa6b9c8dd1308a2a5df97eddb96 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Tue, 18 Jul 2017 23:17:43 -0700 Subject: [PATCH 13/15] fixed indentation in fp.js --- lib/fp.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fp.js b/lib/fp.js index 48207df..0b20710 100644 --- a/lib/fp.js +++ b/lib/fp.js @@ -5,7 +5,7 @@ module.exports = exports = {}; exports.map = (list, ...args) => { if (!list) throw new Error('array not provided'); if (typeof list === 'object') - return Array.prototype.map.call(list, ...args); + return Array.prototype.map.call(list, ...args); }; @@ -27,5 +27,5 @@ exports.reduce = (arr, idx, callback) => { exports.splice = (list, ...args) => { if (!list) throw new Error('array not provided'); if (typeof list === 'object') - return Array.prototype.splice.call(list, ...args); + return Array.prototype.splice.call(list, ...args); }; From 924fdbaa69d71f013ac55de9281fca3c17de86c1 Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Wed, 19 Jul 2017 10:08:05 -0700 Subject: [PATCH 14/15] made requested revisions --- index.js | 1 + lib/fp.js | 2 -- package.json | 2 +- test/test-fp.js | 32 ++++++++++++++++---------------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index 43f3d10..2a15f14 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ let main = module.exports = () => { let list = fp.splice(process.argv, 2); list = fp.map(list, (word) => word.toUpperCase()); let result = list.join(' '); + console.log(result); return result; }; diff --git a/lib/fp.js b/lib/fp.js index 0b20710..f2f9177 100644 --- a/lib/fp.js +++ b/lib/fp.js @@ -4,7 +4,6 @@ module.exports = exports = {}; exports.map = (list, ...args) => { if (!list) throw new Error('array not provided'); - if (typeof list === 'object') return Array.prototype.map.call(list, ...args); }; @@ -26,6 +25,5 @@ exports.reduce = (arr, idx, callback) => { exports.splice = (list, ...args) => { if (!list) throw new Error('array not provided'); - if (typeof list === 'object') return Array.prototype.splice.call(list, ...args); }; diff --git a/package.json b/package.json index acecf1f..7d62c3a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "start": "node index.js", "test": "mocha", - "lint": ".eslint ." + "lint": "eslint" }, "repository": { "type": "git", diff --git a/test/test-fp.js b/test/test-fp.js index 97c1edb..b70ded9 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -8,41 +8,41 @@ describe('fp', () => { it('should throw array not provided error', () => { let mapArrErr = fp.map; expect(mapArrErr).to.throw(Error); - }) + }); it('should return an array with doubled numbers', () => { let validMap = fp.map([1,2,3,4], (n) => { return n * 2 }); expect(validMap).to.be.an('array').that.includes.members([2,4,6,8]); - }) - }) + }); + }); describe('#filter', () =>{ it('should throw array not provided error', () => { let filterArrErr = fp.filter; expect(filterArrErr).to.throw(Error); - }) + }); it('should return an array that is missing the number 2', () => { let validFilter = fp.filter([1, 2, 3, 4], (n) => { return n !== 2 }); expect(validFilter).to.be.an('array').to.not.have.members([2]); - }) - }) + }); + }); describe('#concat', () => { it('should throw an intial array not provided error', () => { let concatArrErr = fp.concat; expect(concatArrErr).to.throw(Error); - }) + }); it('should be an array the is a combination of two arrays', () => { let validConcat = fp.concat([1,2,3], [4,5,6]); expect(validConcat).to.be.an('array').to.include.members([1,2,3,4,5,6]) - }) - }) + }); + }); describe('#reduce', () =>{ it('should throw an intial array not provided error', () => { let reduceArrErr = fp.concat; expect(reduceArrErr).to.throw(Error); - }) + }); it('should reduce an array down to a single value', () => { let validReduce = fp.reduce([0, 1, 2, 3], (acc, n) => {return acc + n }, 0); expect(validReduce).to.equal(6); - }) + }); it('should count amount of each name in an array and return it in an object', () => { var names = ['Alice', 'Bob', 'Tiff', 'Bruce', 'Alice']; var validNameReduce = fp.reduce(names, (allNames, name) => { @@ -55,16 +55,16 @@ describe('fp', () => { return allNames; }, {}); expect(validNameReduce).to.be.an('object'); - }) - }) + }); + }); describe('#splice', () => { it('should throw an intial array not provided error', () =>{ let spliceArrErr = fp.concat; expect(spliceArrErr).to.throw(Error); - }) + }); it('should return [6,7,8]', () => { let result = fp.splice([1,2,3,4,5,6,7,8], 5); expect(result).to.be.an('array').to.include.members([6,7,8]) - }) - }) + }); + }); }) From ed043c276705bac6843b7007ce076f7ffe38a92e Mon Sep 17 00:00:00 2001 From: Jamesbillard12 Date: Wed, 19 Jul 2017 10:14:22 -0700 Subject: [PATCH 15/15] fixed semicolon issue --- test/test-fp.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test-fp.js b/test/test-fp.js index b70ded9..bde0986 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -10,7 +10,7 @@ describe('fp', () => { expect(mapArrErr).to.throw(Error); }); it('should return an array with doubled numbers', () => { - let validMap = fp.map([1,2,3,4], (n) => { return n * 2 }); + let validMap = fp.map([1,2,3,4], (n) => { return n * 2; }); expect(validMap).to.be.an('array').that.includes.members([2,4,6,8]); }); }); @@ -20,7 +20,7 @@ describe('fp', () => { expect(filterArrErr).to.throw(Error); }); it('should return an array that is missing the number 2', () => { - let validFilter = fp.filter([1, 2, 3, 4], (n) => { return n !== 2 }); + let validFilter = fp.filter([1, 2, 3, 4], (n) => { return n !== 2; }); expect(validFilter).to.be.an('array').to.not.have.members([2]); }); }); @@ -31,7 +31,7 @@ describe('fp', () => { }); it('should be an array the is a combination of two arrays', () => { let validConcat = fp.concat([1,2,3], [4,5,6]); - expect(validConcat).to.be.an('array').to.include.members([1,2,3,4,5,6]) + expect(validConcat).to.be.an('array').to.include.members([1,2,3,4,5,6]); }); }); describe('#reduce', () =>{ @@ -40,7 +40,7 @@ describe('fp', () => { expect(reduceArrErr).to.throw(Error); }); it('should reduce an array down to a single value', () => { - let validReduce = fp.reduce([0, 1, 2, 3], (acc, n) => {return acc + n }, 0); + let validReduce = fp.reduce([0, 1, 2, 3], (acc, n) => {return acc + n; }, 0); expect(validReduce).to.equal(6); }); it('should count amount of each name in an array and return it in an object', () => { @@ -64,7 +64,7 @@ describe('fp', () => { }); it('should return [6,7,8]', () => { let result = fp.splice([1,2,3,4,5,6,7,8], 5); - expect(result).to.be.an('array').to.include.members([6,7,8]) + expect(result).to.be.an('array').to.include.members([6,7,8]); }); }); -}) +});