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
5 changes: 5 additions & 0 deletions lab-Anthony/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
26 changes: 26 additions & 0 deletions lab-Anthony/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"env": {
"browser": true,
"node": true,
"commonjs": true,
"jest": true,
"es6": true
},
"globals": {
"err": true,
"req": true,
"res": true,
"next": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"comma-dangle": ["error", "always-multiline"],
"semi": [ "error", "always" ]
}
}
149 changes: 149 additions & 0 deletions lab-Anthony/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@

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

### 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

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history

### 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,visualstudiocode
13 changes: 13 additions & 0 deletions lab-Anthony/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Tools and Context

fp.map has an arity of 2 and accepts an array or a string.
It outputs a new array based on a given function called on an array.

fp.filter has an arity of 2 and accepts arrays.
It outputs a new Array based on a test called within a function on an array.

fp.reduce has an arity of 3 and accepts arrays.
It outputs a number which is determined by a function that is applied against an accumulator and an array.

fp.slice has an arity of 3 and accepts arrays.
It outputs an array based on a beginning and end point on an array.
81 changes: 81 additions & 0 deletions lab-Anthony/__test__/fp.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use strict';

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

describe('Testing map functionality', () => {
test('map() should return [H,E,L,L,O]', () => {
let result = fp.map((word) => word.toUpperCase(), 'Hello');
expect(result).toEqual(['H','E','L','L','O']);
});
test('map() should error with a bad first parameter', () => {
try {
fp.map('this is not a callback', 'this is a valid string');
} catch (error) {
expect(error.message).toEqual('first parameter is not a function');
}
});
test('map() should error with a bad second parameter', () => {
try {
fp.map((word) => word.toUpperCase(), 44);
} catch (error) {
expect(error.message).toEqual('second parameter is not an array or string');
}
});
});
//
describe('Testing filter functionality', () => {
test('filter() should return words shorter than 5 characters', () => {
let result = fp.filter((words) => words.length > 6, ['super', 'neat', 'cool', 'radical', 'exceptional']);
console.log(result);
expect(result).toEqual(['radical','exceptional']);
});
test('filter() should error with a bad first parameter', () => {
try {
fp.filter('this is not a function', ['this', 'is', 'an', 'array']);
} catch (error) {
expect(error.message).toEqual('first parameter is not a function');
}
});
test('filter() should error with a bad second parameter', () => {
try {
fp.filter((words) => words.length > 6, 55);
} catch (error) {
expect(error.message).toEqual('second parameter is not an array');
}
});
});
//
describe('Testing reduce functionality', () => {
test('reduce() should return the sum of all the values', () => {
let result = fp.reduce((accumulator, currentValue) => accumulator + currentValue, [1,2,3], 0);
expect(result).toEqual(6);
});
test('reduce() should return an error with a bad first parameter', () => {
try {
fp.reduce('hello, this is not a function', [1,2,3], 0);
} catch (error) {
expect(error.message).toEqual('first parameter is not a function');
}
});
test('reduce() should return an error with a bad second parameter', () => {
try {
fp.reduce((accumulator, currentValue) => accumulator + currentValue, 66, 0);
} catch (error) {
expect(error.message).toEqual('second parameter is not an array');
}
});
});

describe('Testing slice functionality', () => {
test('slice() should return [steak, kimchi]', () => {
let result = fp.slice(1, 3, ['ramen', 'steak', 'kimchi', 'lecho']);
expect(result).toEqual(['steak', 'kimchi']);
});
test('slice() should return an error with a bad third parameter', () => {
try {
fp.slice(1, 3, 'this is not an array');
} catch (error) {
expect(error.message).toEqual('third parameter is not an array');
}
});
});
26 changes: 26 additions & 0 deletions lab-Anthony/lib/fp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const fp = module.exports = {};

fp.map = function (callback, collection) {
if(!(callback instanceof Function)) throw new Error('first parameter is not a function');
if(!(collection instanceof Array) && (typeof collection !== 'string')) throw new Error('second parameter is not an array or string');
return Array.prototype.map.call(collection, callback);
};

fp.filter = function (callback, collection) {
if(!(callback instanceof Function)) throw new Error('first parameter is not a function');
if(!(collection instanceof Array)) throw new Error('second parameter is not an array');
return Array.prototype.filter.call(collection, callback);
};

fp.reduce = function (callback, collection, initialValue) {
if(!(callback instanceof Function)) throw new Error('first parameter is not a function');
if(!(collection instanceof Array)) throw new Error('second parameter is not an array');
return Array.prototype.reduce.call(collection, callback, initialValue);
};

fp.slice = function (begin, end, collection) {
if(!(collection instanceof Array)) throw new Error('third parameter is not an array');
return Array.prototype.slice.call(collection, begin, end);
};
Loading