From 84d2bd81538b0e61e1f6dab1f140adc729ee500f Mon Sep 17 00:00:00 2001 From: Logan Absher Date: Tue, 18 Jul 2017 15:27:06 -0700 Subject: [PATCH 1/2] all function working correctly, all tests working as expected --- .eslintrc | 21 ++++++++ .gitignore | 140 ++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 9 ++++ lib/fp.js | 46 ++++++++++++++++ package.json | 26 +++++++++ test/fp-test.js | 28 ++++++++++ 6 files changed, 270 insertions(+) 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/fp-test.js 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..ec41ffc --- /dev/null +++ b/.gitignore @@ -0,0 +1,140 @@ +# Created by https://www.gitignore.io/api/osx,vim,node,linux,windows + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### 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 ### +*.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 + +### 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,linux,windows diff --git a/index.js b/index.js new file mode 100644 index 0000000..22e138d --- /dev/null +++ b/index.js @@ -0,0 +1,9 @@ +'use strict'; + +const fp = require('./lib/fp.js'); + +module.exports = exports = {}; + +process.argv.slice(2).forEach( + (val, index, array) => fp.map(array, + (ele) => console.log(ele.toUpperCase()))); diff --git a/lib/fp.js b/lib/fp.js new file mode 100644 index 0000000..6987513 --- /dev/null +++ b/lib/fp.js @@ -0,0 +1,46 @@ +'use strict'; + +module.exports = exports = {} + +exports.map = (arr, callback) => { + if(typeof(arr) !== "object") return 'first parameter must be array'; + if(typeof(callback) !== "function") return 'second parameter must be callback function'; + return Array.prototype.map.call(arr, callback); +}; + +let mapResults = exports.map([1, 2, 3], (ele) => ele * 2); +console.log('map results:', mapResults); + +exports.filter = (arr, callback) => { + if(typeof(arr) !== "object") return 'first parameter must be array'; + if(typeof(callback) !== "function") return 'second parameter must be callback function'; + return Array.prototype.filter.call(arr, callback); +}; + +let filterResults = exports.filter([1, 2, 3], (ele) => ele >= 2); +console.log('filter results:', filterResults); + +exports.reduce = (arr, callback) => { + if(typeof(arr) !== "object") return 'first parameter must be array'; + if(typeof(callback) !== "function") return 'second parameter must be callback function'; + return Array.prototype.reduce.call(arr, callback); +}; + +let reduceResult = exports.reduce([1, 2, 3], (ele, i) => ele + i); +console.log('reduce results:', reduceResult); + +exports.concat = (arrOne, arrTwo) => { + if((typeof(arrOne) !== "object") || (typeof(arrTwo) !== "object")) return 'must have two arrays as parameters'; + return Array.prototype.concat.apply(arrOne, arrTwo); +}; + +let concatResult = exports.concat([1, 2, 3], [4, 5, 6]); +console.log('concat results:', concatResult); + +exports.splice = (arr, parameters) => { + if(typeof(arr) !== "object") return 'first parameter must be array'; + return Array.prototype.splice.call(arr, parameters); +}; + +let spliceResults = exports.splice([1, 2, 3], (1, 1)); +console.log('splice results:', spliceResults); diff --git a/package.json b/package.json new file mode 100644 index 0000000..9dcce76 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "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": { + "lint": "eslint .", + "test": "mocha" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/loganabsher/02-tools_and_context.git" + }, + "author": "Logan Absher", + "license": "MIT", + "bugs": { + "url": "https://github.com/loganabsher/02-tools_and_context/issues" + }, + "homepage": "https://github.com/loganabsher/02-tools_and_context#readme", + "devDependencies": { + "chai": "^4.1.0" + } +} diff --git a/test/fp-test.js b/test/fp-test.js new file mode 100644 index 0000000..4ceb8ba --- /dev/null +++ b/test/fp-test.js @@ -0,0 +1,28 @@ +'use strict'; + +const fp = require('../lib/fp.js'); +const expect = require('chai').expect; + +describe('Fp Module', () => { + it('Should be type \"object\"', () => expect(fp).to.be.an('object')); + describe('#map', () => { + it('Should have map exist', () => expect(fp).to.have.property('map')); + it('Should be type \"function\"', () => expect(fp.map).to.be.a('function')); + }); + describe('#filter', () => { + it('Should have filter exist', () => expect(fp).to.have.property('filter')); + it('Should be type \"function\"', () => expect(fp.filter).to.be.a('function')); + }); + describe('#reduce', () => { + it('Should have reduce exist', () => expect(fp).to.have.property('reduce')); + it('Should be type \"function\"', () => expect(fp.reduce).to.be.a('function')); + }); + describe('#concat', () => { + it('Should have concat exist', () => expect(fp).to.have.property('concat')); + it('Should be type \"function\"', () => expect(fp.concat).to.be.a('function')); + }); + describe('#splice', () => { + it('Should have splice exist', () => expect(fp).to.have.property('splice')); + it('Should be type \"function\"', () => expect(fp.splice).to.be.a('function')); + }); +}); From e7c399e462d6d1a1292ba61cf203f2e3269619ff Mon Sep 17 00:00:00 2001 From: Logan Absher Date: Wed, 19 Jul 2017 11:06:10 -0700 Subject: [PATCH 2/2] fixed linter issues and refactored tests to run in a loop --- lib/fp.js | 18 +++++++++--------- test/fp-test.js | 26 +++++++------------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/lib/fp.js b/lib/fp.js index 6987513..de2b55a 100644 --- a/lib/fp.js +++ b/lib/fp.js @@ -1,10 +1,10 @@ 'use strict'; -module.exports = exports = {} +module.exports = exports = {}; exports.map = (arr, callback) => { - if(typeof(arr) !== "object") return 'first parameter must be array'; - if(typeof(callback) !== "function") return 'second parameter must be callback function'; + if(typeof(arr) !== 'object') return 'first parameter must be array'; + if(typeof(callback) !== 'function') return 'second parameter must be callback function'; return Array.prototype.map.call(arr, callback); }; @@ -12,8 +12,8 @@ let mapResults = exports.map([1, 2, 3], (ele) => ele * 2); console.log('map results:', mapResults); exports.filter = (arr, callback) => { - if(typeof(arr) !== "object") return 'first parameter must be array'; - if(typeof(callback) !== "function") return 'second parameter must be callback function'; + if(typeof(arr) !== 'object') return 'first parameter must be array'; + if(typeof(callback) !== 'function') return 'second parameter must be callback function'; return Array.prototype.filter.call(arr, callback); }; @@ -21,8 +21,8 @@ let filterResults = exports.filter([1, 2, 3], (ele) => ele >= 2); console.log('filter results:', filterResults); exports.reduce = (arr, callback) => { - if(typeof(arr) !== "object") return 'first parameter must be array'; - if(typeof(callback) !== "function") return 'second parameter must be callback function'; + if(typeof(arr) !== 'object') return 'first parameter must be array'; + if(typeof(callback) !== 'function') return 'second parameter must be callback function'; return Array.prototype.reduce.call(arr, callback); }; @@ -30,7 +30,7 @@ let reduceResult = exports.reduce([1, 2, 3], (ele, i) => ele + i); console.log('reduce results:', reduceResult); exports.concat = (arrOne, arrTwo) => { - if((typeof(arrOne) !== "object") || (typeof(arrTwo) !== "object")) return 'must have two arrays as parameters'; + if((typeof(arrOne) !== 'object') || (typeof(arrTwo) !== 'object')) return 'must have two arrays as parameters'; return Array.prototype.concat.apply(arrOne, arrTwo); }; @@ -38,7 +38,7 @@ let concatResult = exports.concat([1, 2, 3], [4, 5, 6]); console.log('concat results:', concatResult); exports.splice = (arr, parameters) => { - if(typeof(arr) !== "object") return 'first parameter must be array'; + if(typeof(arr) !== 'object') return 'first parameter must be array'; return Array.prototype.splice.call(arr, parameters); }; diff --git a/test/fp-test.js b/test/fp-test.js index 4ceb8ba..aaf43f9 100644 --- a/test/fp-test.js +++ b/test/fp-test.js @@ -3,26 +3,14 @@ const fp = require('../lib/fp.js'); const expect = require('chai').expect; +const funcNames = ['map', 'filter', 'reduce', 'concat', 'splice', 'notFunctionFail']; + describe('Fp Module', () => { it('Should be type \"object\"', () => expect(fp).to.be.an('object')); - describe('#map', () => { - it('Should have map exist', () => expect(fp).to.have.property('map')); - it('Should be type \"function\"', () => expect(fp.map).to.be.a('function')); - }); - describe('#filter', () => { - it('Should have filter exist', () => expect(fp).to.have.property('filter')); - it('Should be type \"function\"', () => expect(fp.filter).to.be.a('function')); - }); - describe('#reduce', () => { - it('Should have reduce exist', () => expect(fp).to.have.property('reduce')); - it('Should be type \"function\"', () => expect(fp.reduce).to.be.a('function')); - }); - describe('#concat', () => { - it('Should have concat exist', () => expect(fp).to.have.property('concat')); - it('Should be type \"function\"', () => expect(fp.concat).to.be.a('function')); - }); - describe('#splice', () => { - it('Should have splice exist', () => expect(fp).to.have.property('splice')); - it('Should be type \"function\"', () => expect(fp.splice).to.be.a('function')); + funcNames.forEach((ele) => { + describe(`#${ele}`, () => { + it(`Should have ${ele} exist`, () => expect(fp).to.have.property(ele)); + it('Should be type \"function\"', () => expect(fp[ele]).to.be.a('function')); + }); }); });