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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## Configuration
Configure the root of your repository with the following files and directories. Thoughtfully name and organize any additional configuration or module files.
* **README.md** - contains documentation
* **.gitignore** - contains a [robust](http://gitignore.io) `.gitignore` file
* **.gitignore** - contains a [robust](http://gitignore.io) `.gitignore` file
* **.eslintrc.json** - contains the course linter configuration
* **.eslintignore** - contains the course linter ignore configuration
* **package.json** - contains npm package config
Expand All @@ -22,7 +22,7 @@ Configure the root of your repository with the following files and directories.

## Feature Tasks
#### fp Module
Create a NodeJS module in the lib/ directory named fp.js that exports an object. Create stand-alone `map`, `filter`, `reduce`, and `slice` functions using the `call` and `apply` function methods. Define each function using ES6 lexical arrow function syntax.
Create a NodeJS module in the lib/ directory named fp.js that exports an object. Create stand-alone `map`, `filter`, `reduce`, and `slice` functions using the `call` and `apply` function methods. Define each function using ES6 lexical arrow function syntax.

In each function error-check each parameter and throw an Error with a meaningful message if the function is invoked with invalid arguments. Do not use any third party libraries in the FP module.

Expand All @@ -34,7 +34,7 @@ In each function error-check each parameter and throw an Error with a meaningful
#### FP Module Tests
Create a NodeJS module in the \_\_test\_\_/ named fp.test.js that asserts the correctness of the fp module.

* Use TDD `describe` and `test` methods to define descriptive tests
* Use TDD `describe` and `test` methods to define descriptive tests
* Each `test` callback should aim to test a small well defined feature of a function
* Write tests to ensure the fp module functions correctly error-check parameters
* Assert that the correct errors are thrown with invalid arguments
Expand Down
5 changes: 5 additions & 0 deletions lab-matt/.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-matt/.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-matt/.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
24 changes: 24 additions & 0 deletions lab-matt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 02: Node Ecosystem
Description: **Lab 02 of Code Fellows JavaScript 401d19** </br>
Author: **Matthew LeBlanc** </br>
Date: **11/28/17**

### fp.map(callback, collection)
The `fp.map` method uses the `call` method to create a new array by using the `array.prototype.map` method that takes an arity of two which one is the array, and the other is a callback function defining what the map method should do to return a new array.

expected data is numbers multiplied by two and only allows numbers in the array.

### fp.filter(callback, collection)
The `fp.filter` method uses the `call` method to create a new array by using the `array.prototype.filter` method that takes an arity of two which one is the array, and the other is a callback function defining what the filter method should do to return a filtered array.

expected data is words over `.length` of 5 to be filtered and numbers over fifty.

### fp.reduce(callback, initialState, collection)
The `fp.reduce` method uses the `call` method to reduce an array into a single data by using the `array.prototype.reduce` method that takes an arity of three which one is the array, another is a callback function defining how the array should reduce, and the third is the initial state of the reduced array.

expected data is the sum of numbers and concatenated strings with spaces.

### fp.slice(begin, end, collection)
The `fp.slice` method uses the `call` method to create a new array by removing certain sections of the array with the `array.prototype.slice` method that takes an arity of three which one is the starting point of the slice, the second is the end point of the slice, and the third is the array to be sliced.

expected data is removal of outer elements of an array and removal of all elements in an array.
157 changes: 157 additions & 0 deletions lab-matt/__test__/fp-curry.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
'use strict';

const curry = require('../lib/fp-curry.js');
const map = function(obj) {
return curry.type('map', obj);
};
const filter = function(obj) {
return curry.type('filter', obj);
};
const reduce = function(obj) {
return curry.type('reduce', obj);
};
const slice = function(obj) {
return curry.type('slice', obj);
};

describe('fp-curry.js', () => {
// ---------------------------------------------
// MAP
// ---------------------------------------------
describe('curry map method', () => {
// ------METHODS/PARAMETERS-------
const multiplyByTwo = function(currentElement) {
if (typeof(currentElement) !== 'number') throw new TypeError('array can only include numbers');
return currentElement * 2;
};

// --------TEST FUNCTIONS---------
let successfulTest = function(collection, method, expected) {
expect(map({
collection: collection,
callback: method,
})).toEqual(expected);
};

let throwTest = function(collection, method) {
expect(() => {
map({
collection: collection,
callback: method,
});
}).toThrow();
};

// -----------TESTS---------------
test('multiply by two - [0, 1, 2] => [0, 2, 4]', () => {
successfulTest([0, 1, 2], multiplyByTwo, [0, 2, 4]);
});

test('multiply by two - empty array returns an empty array', () => {
successfulTest([], multiplyByTwo, []);
});

test('multiply by two - if any element is not a number will throw an error', () => {
throwTest([1, 4, null], multiplyByTwo);
});
});

// ---------------------------------------------
// FILTER
// ---------------------------------------------
describe('curry filter method', () => {
// ------METHODS/PARAMETERS-------
const filterWordsOverFive = function(currentElement) {
return currentElement.length > 5;
};
const filterNumbersOverFifty = function(currentElement) {
return currentElement > 50;
};

// --------TEST FUNCTIONS---------
let successfulTest = function(collection, method, expected) {
expect(filter({
collection: collection,
callback: method,
})).toEqual(expected);
};

// -----------TESTS---------------
test(`words over length of five - ['foobar', 'truthy', 'falsy', 'true', 'one'] => ['foobar', 'truthy']`, () => {
successfulTest(['foobar', 'truthy', 'falsy', 'true', 'one'], filterWordsOverFive, ['foobar', 'truthy']);
});

test(`words over length of five - ['random', 'large', 'orange', 'banana', 'vehicle'] => ['random', 'orange', 'banana', 'vehicle']`, () => {
successfulTest(['random', 'large', 'orange', 'banana', 'vehicle'], filterWordsOverFive, ['random', 'orange', 'banana', 'vehicle']);
});

test('numbers over fifty - [34, 23, 1235432, 268234, 372] => [1235432, 268234, 372]', () => {
successfulTest([34, 23, 1235432, 268234, 372], filterNumbersOverFifty, [1235432, 268234, 372]);
});

test('numbers over fifty - [50, 40, 30, 60] => [60]', () => {
successfulTest([50, 40, 30, 60], filterNumbersOverFifty, [60]);
});
});

// ---------------------------------------------
// REDUCE
// ---------------------------------------------
describe('curry reduce method', () => {
// ------METHODS/PARAMETERS-------
const reduceNumbers = (accumulator, currentElement) => {
return accumulator + currentElement;
};
const concatStrings = (accumulator, currentElement) => {
if (accumulator === '') return currentElement;
return `${accumulator} ${currentElement}`;
};

// --------TEST FUNCTIONS---------
let successfulTest = function(collection, method, initialState, expected) {
expect(reduce({
collection: collection,
callback: method,
initialState: initialState,
})).toEqual(expected);
};

// -----------TESTS---------------
test('reduce [3, 6, 10] to 19', () => {
successfulTest([3, 6, 10], reduceNumbers, 0, 19);
});

test(`reduce ['hello', 'there', 'friend'] => 'hello there friend'`, () => {
successfulTest(['hello', 'there', 'friend'], concatStrings, '', 'hello there friend');
});

test('reduce empty string => returns empty string', () => {
successfulTest('', concatStrings, '', '');
});
});

// ---------------------------------------------
// SLICE
// ---------------------------------------------
describe('curry slice method', () => {
const array1 = [3, 'two', null, 2, undefined];

// --------TEST FUNCTIONS---------
let successfulTest = function(collection, begin, end, expected) {
expect(slice({
collection: collection,
begin: begin,
end: end,
})).toEqual(expected);
};

// -----------TESTS---------------
test(`begin: 1, end: -1 removes outer elements of array`, () => {
successfulTest(array1, 1, -1, ['two', null, 2]);
});

test(`begin: 0, end: 0 empties the array`, () => {
successfulTest(array1, 0, 0, []);
});
});
});
Loading