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
Binary file added .DS_Store
Binary file not shown.
48 changes: 0 additions & 48 deletions README.md

This file was deleted.

5 changes: 5 additions & 0 deletions lab-pedja/.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-pedja/.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" ]
}
}
148 changes: 148 additions & 0 deletions lab-pedja/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# 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
17 changes: 17 additions & 0 deletions lab-pedja/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
![cf](https://i.imgur.com/7v5ASc8.png) 02: Lab Tools and Context
======

## Feature Tasks
#### fp Module
Created in lib/ directory fp.js constains fp module that exports an object.
fp module has 4 stand alone functions `map`, `filter`, `reduce`, and `slice`.

* Both `fp.map` and `fp.filter` take 2 parameters `(callback, collection)` and will return new Array.
Map will return array with items multiplied with 2.
Filter function will return an array of numbers that are higher than 3.
`callback` parameter has to be a function and `collection` has to be an object. If `fp.map` and `fp.filter` are invoked with not valid arguments exception will be thrown and new TypeError will be printed.

* `fp.reduce` takes three parameters `(callback, initialState, collection)` and returns a sum of all items in collection array.
If function is invoked with callback argument that is not a function or with initialValue argument that is not a number, exception will be thrown and new TypeError will be printed.

* `fp.slice` takes three parameters `(begin, end, collection)` and returns new array.If function is invoked with `begin` and `end` arguments that are not a number, exception will be thrown and new TypeError will be printed.
101 changes: 101 additions & 0 deletions lab-pedja/__test__/fp.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';

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

describe('fp.js', () => {

// testing fp.map function
describe('fp.map', () => {
test('returns array with items multiplied with 2', () => {
expect(fp.map(
(num) => num * 2,
[0, 1, 2]
)).toEqual([0, 2, 4]);
});

test('exception will be thrown if error occurs', () => {
expect(
() => {
fp.map('I\'m not a function ()', [0, 1, 2]);
}).toThrow();
expect(
() => {
fp.map(
(num) => num * 2,
'one'
);
}).toThrow();
});
});

// testing fp.filter function
describe('fp.filter', () => {
test('return value should be number higher than 3', () => {
expect(fp.filter(
(num) => num > 3,
[1, 2, 3, 4, 5]
)).toEqual([4, 5]);
});

test('exception will be thrown if error occurs', () => {
expect(
() => {
fp.filter('I\'m not a function ()', [0, 1, 2]);
}).toThrow();
expect(
() => {
fp.filter(
(num) => num > 3,
'one'
);
}).toThrow();
});
});

// testing fp.reduce function
describe('fp.reduce', () => {
test('return value should be sum of the collection if callback is adding them', () => {
expect(fp.reduce(
(accu, curr) => {
return accu + curr;
},
[1, 2, 3],
10
)).toBe(16);
});

test('exception will be thrown if error occurs', () => {
expect(
() => {
fp.reduce('I\'m not a function ()', [0, 1, 2], 10);
}
).toThrow();
expect(
() => {
fp.reduce(
(accu, curr) => {
return accu + curr;
},
[0, 1, 2],
'someString');
}
).toThrow();
});
});

//testing fp.slice function
describe('fp.slice', () => {
test('return new array with first 3 items of an existing array', () => {
expect(fp.slice(0, 3, [0, 1, 2, 3, 4])).toEqual([0, 1, 2]);
});
test('exception will be thrown if error occurs', () => {
expect(
() => {
fp.slice('negaiveNumber', -1, [0, 1, 2])
}
).toThrow();
});

});

});
1 change: 1 addition & 0 deletions lab-pedja/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';
33 changes: 33 additions & 0 deletions lab-pedja/lib/fp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

const fp = module.exports = {};

fp.map = (callback, collection) => {
if(typeof callback !== 'function')
throw new TypeError('<callback> should be a function');
if(typeof collection !== 'object')
throw new TypeError('<collection> should be an array like object');
return Array.prototype.map.call(collection, callback);
};

fp.filter = (callback, collection) => {
if(typeof callback !== 'function')
throw new TypeError('<callback> should be a function');
if(typeof collection !== 'object')
throw new TypeError('<collection> should be an array like object');
return Array.prototype.filter.call(collection, callback);
};

fp.reduce = (callback, collection, initialValue) => {
if(typeof callback !== 'function')
throw new TypeError('<callback> is not a function');
if(typeof initialValue !== 'number')
throw new TypeError('<initialValue> is not a number')
return Array.prototype.reduce.call(collection, callback, initialValue);
};

fp.slice = (begin, end, collection) => {
if(typeof begin !== 'number' || typeof end !== 'number' )
throw new TypeError('<begin> or <end> argument is not a number');
return Array.prototype.slice.call(collection, begin, end);
};
Loading