Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -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"
}
128 changes: 128 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@

# Created by https://www.gitignore.io/api/osx,vim,node,windows

### 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,windows
/lab-eddie/node_modules
57 changes: 57 additions & 0 deletions lab-eddie/lib/fp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

module.exports = exports = {};

exports.argumentLengthError = (argLength, expectedLength) => {
if(argLength < expectedLength) throw new Error(`exports.requires ${expectedLength} arguments. Only ${argLength} provided.`);
};
exports.typeError = (objType, expectedType) => {
if(objType !== expectedType) throw new Error(`exports.expected ${expectedType} type parameter but recieved ${objType} instead.`);
};

exports.isArray = (arr) => Array.isArray(arr) ? 'array' : typeof arr;


exports.map = function(arr, callback) {
let argumentLength = arguments.length;
this.argumentLengthError(argumentLength, 2);
this.typeError(this.isArray(arr), 'array');
this.typeError(typeof callback, 'function');
return Array.prototype.map.call(arr, callback);
};

exports.filter = function(arr, callback) {
let argumentLength = arguments.length;
this.argumentLengthError(argumentLength, 2);
this.typeError(this.isArray(arr), 'array');
this.typeError(typeof callback, 'function');
return Array.prototype.filter.call(arr, callback);
};

exports.reduce = function(arr, callback, count) {

let argumentLength = arguments.length;
this.argumentLengthError(argumentLength, 2);
if(count === undefined) count = arr[0];

this.typeError(this.isArray(arr), 'array');
this.typeError(typeof callback, 'function');
return Array.prototype.reduce.call(arr, callback, count);
};

exports.concat = function(firstArray, secondArray) {
let argumentLength = arguments.length;
this.argumentLengthError(argumentLength, 2);
this.typeError(this.isArray(firstArray), 'array');
this.typeError(this.isArray(secondArray), 'array');
return Array.prototype.concat.apply(firstArray, secondArray);
},

exports.splice = function(arr, startingIndex, amountToDelete, ...items) {
let argumentLength = arguments.length;
this.argumentLengthError(argumentLength, 2);
this.typeError(this.isArray(arr), 'array');
this.typeError(typeof startingIndex, 'number');
if(amountToDelete) this.typeError(typeof amountToDelete, 'number');
return Array.prototype.splice.call(arr, startingIndex, amountToDelete, ...items);
};
20 changes: 20 additions & 0 deletions lab-eddie/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "lab-eddie",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "mocha"
},
"scripts": {
"test": "mocha",
"lint": "eslint"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"chai": "^4.1.0",
"mocha": "^3.4.2"
}
}
96 changes: 96 additions & 0 deletions lab-eddie/test/fp-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
'use strict';

const fp = require('../lib/fp.js');
const expect = require('chai').expect;

let testingArray = [1, 5, 7, 8];
let secondTestArray = [9, 1, 1, 4];

describe('Test for fp module', () => {

describe('#map', () => {

it('Should return a new modified array', () => {
let mappedArray = fp.map(testingArray, (val) => val + 1);
let secondMappedArray = fp.map(testingArray, (val) => Math.pow(val, 2));
expect(mappedArray).to.deep.equal([2, 6, 8, 9]);
expect(secondMappedArray).to.deep.equal([1, 25, 49, 64]);
});

it('Should throw an error when invalid arguements are entered', () => {
expect(fp.map.bind(fp)).to.throw(Error);
expect(fp.map.bind(fp, [1, 2, 3, 4])).to.throw(Error);
expect(fp.map.bind(fp, [1, 2, 3], 'not a callback')).to.throw(Error);
expect(fp.map.bind(fp, 'not an array', (val) => 1 + val)).to.throw(Error);
});

});

describe('#filter', () => {

it('Should return a new filtered array', () => {
let filterArray = fp.filter(testingArray, (val) => val < 6);
let secondFilterArray = fp.filter(testingArray, (val) => val > 5);
expect(filterArray).to.deep.equal([1, 5]);
expect(secondFilterArray).to.deep.equal([7, 8]);
});

it('Should throw an error when invalid arguements are entered', () => {
expect(fp.filter.bind(fp)).to.throw(Error);
expect(fp.filter.bind(fp, [1, 2, 3, 4])).to.throw(Error);
expect(fp.filter.bind(fp, [1, 2, 3], 'not a callback')).to.throw(Error);
expect(fp.filter.bind(fp, 'not an array', (val) => 1 + val)).to.throw(Error);
});
})

describe('#reduce', () => {

it('Should return a reduced array', () => {
let reduceArray = fp.reduce(testingArray, (count, val) => {
count += val;
return count;
}, 0);
let secondReduceArray = fp.reduce(testingArray, (count, val) => {
count.push(val + 1);
return count;
}, [1]);
expect(reduceArray).to.equal(21);
expect(secondReduceArray).to.deep.equal([1, 2, 6, 8, 9]);
});

it('Should throw an error when invalid arguements are entered', () => {
expect(fp.reduce.bind(fp)).to.throw(Error);
expect(fp.reduce.bind(fp, 1)).to.throw(Error);
expect(fp.reduce.bind(fp, [], 1)).to.throw(Error);
expect(fp.reduce.bind(fp, 'a', (val) => val)).to.throw(Error);
});
});

describe('#concat', () => {

it('Should return a new concated array', () => {
expect(fp.concat(testingArray, secondTestArray))
.to.deep.equal([1, 5, 7, 8, 9, 1, 1, 4]);
});

it('Should throw an error when invalid arguements are entered', () => {
expect(fp.concat.bind(fp)).to.throw(Error);
expect(fp.concat.bind(fp, [], 'a')).to.throw(Error);
expect(fp.concat.bind(fp, 'a', [])).to.throw(Error);
});
});
describe('#splice', () => {

it('Should return a new spliceed array', () => {
expect(fp.splice(testingArray, 0, 2)).to.deep.equal([1, 5]);
expect(fp.splice(testingArray, 0, 1, 4, 5, 6, 7)).to.deep.equal([7]);
expect(testingArray).to.deep.equal([4, 5, 6, 7, 8])
});

it('Should throw an error when invalid arguements are entered', () => {
expect(fp.splice.bind(fp)).to.throw(Error);
expect(fp.splice.bind(fp, 'a', 1)).to.throw(Error);
expect(fp.splice.bind(fp, 3, 'a')).to.throw(Error);
});
});
});