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 lab02-fredric/.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 lab02-fredric/.eslintrc.json
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" ]
}
}
119 changes: 119 additions & 0 deletions lab02-fredric/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Created by https://www.gitignore.io/api/osx,vim,node,linux

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

# End of https://www.gitignore.io/api/osx,vim,node,linux
25 changes: 25 additions & 0 deletions lab02-fredric/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


## Lab 02 class 401d19 Documentation

The exported values of fp.js is an object named fp.

Functions
<fp.map> has an arity of 2 callback(function), collection(array).
returns a new <array> with the callback <function> applied on the original elements unless there are errors.
It’s limitations are that it should take any array and throws a TypeError if collection input is not an array.

<fp.reduce> has an arity of 3 callback(function), collection(array)and initialValue(string, number)
will return a single value when applying a <function> on a <accumulator> and the <array>.
It’s limitations are that it should take any array and optional initialValue and throws a TypeError if collection input is not an array.
And will throw a TypeError if callback is not a function.

<fp.filter> has an arity of 2 callback(function), collection(array).
will return an <array> of elements that are passed through the callback filter
It’s limitations are that it should take any array and throws a TypeError if collection input is not an array.
And will throw a TypeError if callback is not a function.

<fp.slice> has an arity: 3 begin(number), end(number), collection(array)
will return a new <array> with numbers sliced from the original <array>
It’s limitations are that it should take any array and will throw a TypeError if collection input is not an array.
And will throw a TypeError if begin or end are not a number.
108 changes: 108 additions & 0 deletions lab02-fredric/__test__/fp-curry.testy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
'use strict';

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

describe('<fp.test.js>', () => {
describe('tests for <fp.map>', () => {
test('fp.map should return a new <array> with the callback <function> applied on the original elements unless there are errors', () => {
expect(fp.map(
n => n * 2, [1, 2, 3]
)).toEqual([2, 4, 6]);
});
test('throw an exception if NOT an <array>', () => {
expect(() => {
fp.map((n => n * 2),
'This is a string, NOT an <array>');
}).toThrow();
});
});

describe('tests <fp.reduce>', () => {
test('fp.reduce will return a single value when applying a <function> on a <accumulator> and the <array>', () => {
expect(fp.reduce(
(accumulator, currentValue) => {
return accumulator + currentValue;
}, [1, 2, 3],
0
)).toBe(6);
});

test('An exception will be thrown if callback is NOT a <function>', () => {
expect(() => {
fp.reduce('This is a STRING, NOT a <function>', [1, 2, 3],
0);
}).toThrow();
expect(() => {
fp.reduce(
[1, 2, 3], [1, 2, 3],
0);
}).toThrow();
});

test('An exception will be thrown if the collection is NOT an <array>', () => {
expect(() => {
fp.reduce(
(accumulator, currentValue) => {
return accumulator + currentValue;
},
'This is a STRING, NOT an <array>',
0);
}).toThrow();
});

describe('Tests for <fp.filter>', () => {
test('<fp.filter> will return an <array> of elements that passed through the callback filter', () => {
expect(fp.filter(
(n => n < 3),
[1, 2, 3]
)).toEqual([1, 2]);
});

test('An exception will be thrown if the collection is NOT a <array>', () => {
expect(() => {
fp.filter(n => n < 3,
'This is a STRING, NOT an <array>');
}).toThrow();
});

test('An exception will be thrown if the callback is NOT a <function>', () => {
expect(() => {
fp.filter(
'string',
[1,2,3]);
}).toThrow();
});
});

describe('tests for <fp.slice>', () => {
test('<fp.slice> will return a new <array> with numbers sliced from the original <array>', ()=> {
expect(fp.slice(1, 4, [1, 2, 3, 5, 6]
)).toEqual([2, 3, 5]);
});

test('An exception will be thrown if collection is not a <array>', () => {
expect(() => {
fp.slice(
1,
4,
'collection not an array');
}).toThrow();
});

test('An exception will be thrown if begin or end is not a number', () => {
expect(() => {
fp.slice(
'string',
4,
[1,2,3,5,6,7,8]);
}).toThrow();
expect(() => {
fp.slice(
1,
true,
[1,2,3,5,6,7,8]);
}).toThrow();
});
});
});
});
108 changes: 108 additions & 0 deletions lab02-fredric/__test__/fp.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
'use strict';

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

describe('<fp.test.js>', () => {
describe('tests for <fp.map>', () => {
test('fp.map should return a new <array> with the callback <function> applied on the original elements unless there are errors', () => {
expect(fp.map(
n => n * 2, [1, 2, 3]
)).toEqual([2, 4, 6]);
});
test('throw an exception if NOT an <array>', () => {
expect(() => {
fp.map((n => n * 2),
'This is a string, NOT an <array>');
}).toThrow();
});
});

describe('tests <fp.reduce>', () => {
test('fp.reduce will return a single value when applying a <function> on a <accumulator> and the <array>', () => {
expect(fp.reduce(
(accumulator, currentValue) => {
return accumulator + currentValue;
}, [1, 2, 3],
0
)).toBe(6);
});

test('An exception will be thrown if callback is NOT a <function>', () => {
expect(() => {
fp.reduce('This is a STRING, NOT a <function>', [1, 2, 3],
0);
}).toThrow();
expect(() => {
fp.reduce(
[1, 2, 3], [1, 2, 3],
0);
}).toThrow();
});

test('An exception will be thrown if the collection is NOT an <array>', () => {
expect(() => {
fp.reduce(
(accumulator, currentValue) => {
return accumulator + currentValue;
},
'This is a STRING, NOT an <array>',
0);
}).toThrow();
});

describe('Tests for <fp.filter>', () => {
test('<fp.filter> will return an <array> of elements that passed through the callback filter', () => {
expect(fp.filter(
(n => n < 3),
[1, 2, 3]
)).toEqual([1, 2]);
});

test('An exception will be thrown if the collection is NOT a <array>', () => {
expect(() => {
fp.filter(n => n < 3,
'This is a STRING, NOT an <array>');
}).toThrow();
});

test('An exception will be thrown if the callback is NOT a <function>', () => {
expect(() => {
fp.filter(
'string',
[1,2,3]);
}).toThrow();
});
});

describe('tests for <fp.slice>', () => {
test('<fp.slice> will return a new <array> with numbers sliced from the original <array>', ()=> {
expect(fp.slice(1, 4, [1, 2, 3, 5, 6]
)).toEqual([2, 3, 5]);
});

test('An exception will be thrown if collection is not a <array>', () => {
expect(() => {
fp.slice(
1,
4,
'collection not an array');
}).toThrow();
});

test('An exception will be thrown if begin or end is not a number', () => {
expect(() => {
fp.slice(
'string',
4,
[1,2,3,5,6,7,8]);
}).toThrow();
expect(() => {
fp.slice(
1,
true,
[1,2,3,5,6,7,8]);
}).toThrow();
});
});
});
});
Loading