diff --git a/lab-sharmarke/.eslintignore b/lab-sharmarke/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/lab-sharmarke/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/lab-sharmarke/.eslintrc b/lab-sharmarke/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/lab-sharmarke/.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/lab-sharmarke/.gitignore b/lab-sharmarke/.gitignore new file mode 100644 index 0000000..02bd5f4 --- /dev/null +++ b/lab-sharmarke/.gitignore @@ -0,0 +1,141 @@ + +# Created by https://www.gitignore.io/api/vim,node,macos,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* + +### 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 + + +### 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/vim,node,macos,linux,windows diff --git a/lab-sharmarke/lib/fp.js b/lab-sharmarke/lib/fp.js new file mode 100644 index 0000000..7293153 --- /dev/null +++ b/lab-sharmarke/lib/fp.js @@ -0,0 +1,18 @@ +'use strict'; + +module.exports = exports = {}; + +// Map +exports.map = (arr, callback) => Array.prototype.map.call(arr, callback); + +// Filter +exports.filter = (arr, callback) => Array.prototype.filter.call(arr, callback); + +// Reduce +exports.reduce = (arr, callback, init = 0) => Array.prototype.reduce.call(arr, callback, init); + +//Concat +exports.concat = (arr1, arr2) => Array.prototype.concat.apply(arr1, arr2); + +//Splice +exports.splice = (arr, start, deleteCount, item) => Array.prototype.splice.call(arr, start, deleteCount, item); diff --git a/lab-sharmarke/package.json b/lab-sharmarke/package.json new file mode 100644 index 0000000..7c0e7f6 --- /dev/null +++ b/lab-sharmarke/package.json @@ -0,0 +1,20 @@ +{ + "name": "lab-sharmarke", + "version": "1.0.0", + "description": "", + "main": "index.js", + "directories": { + "test": "tests" + }, + "scripts": { + "test": "mocha", + "lint": "eslint ." + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "chai": "^4.1.0", + "mocha": "^3.4.2" + } +} diff --git a/lab-sharmarke/test/fp-test.js b/lab-sharmarke/test/fp-test.js new file mode 100644 index 0000000..bf209bb --- /dev/null +++ b/lab-sharmarke/test/fp-test.js @@ -0,0 +1,70 @@ +'use strict'; + +const expect = require('chai').expect; +const fp = require('../lib/fp.js'); + +describe('Fp', () => { + + describe('#map', () => { + it('should return 3,4,5,6,7', () => { + let arr = [1,2,3,4,5]; + let result = fp.map(arr, n => n + 2); + expect(result).to.deep.equal([3,4,5,6,7]); + }); + + it('should throw an error', () => { + let result = fp.map; + expect(result).to.throw(Error); + }); + }); + + describe('#filter', () => { + it('should return 1,2,3', () => { + let arr = [1,2,3,4,5]; + let result = fp.filter(arr, n => n <= 3); + expect(result).to.deep.equal([1,2,3]); + }); + + it('should throw an error', () => { + let result = fp.filter; + expect(result).to.throw(Error); + }); + }); + + describe('#reduce', () => { + it('should return 15', () => { + let arr = [1,2,3,4,5]; + let result = fp.reduce(arr, (n,o) => n+o); + expect(result).to.deep.equal(15); + }); + + it('should throw an error', () => { + let result = fp.reduce; + expect(result).to.throw(Error); + }); + }); + + describe('#splice', () => { + it('should return hello', () => { + let result = fp.splice([1, 2, 3, 'hello', 5], 3, 1, 4); + console.log(result); + expect(result).to.deep.equal(['hello']); + }); + + it('should throw an error', () => { + let result = fp.reduce; + expect(result).to.throw(Error); + }); + }); + + describe('#concat', () => { + it('should return [1,2,3,4,5]', () => { + let result = fp.concat([1,2,3],[4,5]); + expect(result).to.deep.equal([1,2,3,4,5]); + }); + it('should throw an error', () => { + let result = fp.reduce; + expect(result).to.throw(Error); + }); + }); +});