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 .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
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"
}
136 changes: 136 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Created by https://www.gitignore.io/api/osx,vim,node,macos,windows

### macOS ###
*.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

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

# Icon must end with two \r

# Thumbnails

# Files that might appear in the root of a volume

# Directories potentially created on remote AFP share

### 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,macos,windows
38 changes: 7 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
![cf](https://i.imgur.com/7v5ASc8.png) 02: Tools and Context
======

## To Submit this Assignment
* fork this repository & create a new branch for your work
* write all of your code in a directory named `lab-` + `<your name>` **e.g.** `lab-susan`
* push to your repository
* submit a pull request to this repository
* submit a link to your PR in canvas
* write a question and observation on canvas

## Directions
* create a `/lib` and `/test` directory
* add a robust `.gitignore` file
* include a `package.json`
* include the provided `.eslintrc` file
* create a `lint` script for running eslint
* create a `test` script for running mocha
* create a `lib/fp.js` file for holding the following:
* create stand alone `map`, `filter`, `reduce`, `concat`, and `splice` functions using the `call`, and `apply` methods we discussed today
* you are welcome to use/experiment with `bind` too!
* *note:* - all functions should be created using the es6 lexical arrow function syntax

# Tests
* create a test for each of your custom functions in `lib/fp.js`
* note - feel free to create additional tests, if you choose!

## Bonus 2pts
* create a CLI (`index.js`) that will use your new `map` function to uppercase all command line arguments and print them to the screen: 1pt
* **hint:** - you'll want to check out the `process` object (and it's methods) to get an array of provided command line arguments
* test your CLI: 1pt
## Lab-James Lab-02 Documentation
* index.js calls function 'main' function which returns CLI parameters as uppercase words using the fp.splice method from ./lib/fp.js.
* ./lib/fp.js defines the map, filter, reduce, concat, and splice methods using both call and apply.
* Tests
* ./test/fp-test.js tests the above methods
* **Stretch Goal:** ./test/index-test.js tests the index.js CLI functionality.
* Project passes Mocha (chai) tests and esLint.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

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

let main = module.exports = () => {
let list = fp.splice(process.argv, 2);
list = fp.map(list, (word) => word.toUpperCase());
let result = list.join(' ');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to at some point print them out to the screen in their capital form.

console.log(result);
return result;
};

main();
29 changes: 29 additions & 0 deletions lib/fp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

module.exports = exports = {};

exports.map = (list, ...args) => {
if (!list) throw new Error('array not provided');
return Array.prototype.map.call(list, ...args);
};


exports.filter = (arr, callback) => {
if (!arr) throw new Error('array not provided');
return Array.prototype.filter.call(arr, callback);
};

exports.concat = (arr1, arr2) => {
if (!arr1) throw new Error('initial array not provided');
return Array.prototype.concat.apply(arr1, arr2);
};

exports.reduce = (arr, idx, callback) => {
if (!arr) throw new Error('array not provided');
return Array.prototype.reduce.call(arr, idx, callback);
};

exports.splice = (list, ...args) => {
if (!list) throw new Error('array not provided');
return Array.prototype.splice.call(list, ...args);
};
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "02-tools_and_context",
"version": "1.0.0",
"description": "![cf](https://i.imgur.com/7v5ASc8.png) 02: Tools and Context ======",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"start": "node index.js",
"test": "mocha",
"lint": "eslint"
},
"repository": {
"type": "git",
"url": "git+https://github.com/codefellows-javascript-401d17/02-tools_and_context.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/codefellows-javascript-401d17/02-tools_and_context/issues"
},
"homepage": "https://github.com/codefellows-javascript-401d17/02-tools_and_context#readme",
"devDependencies": {
"chai": "^4.1.0",
"expect": "^1.20.2",
"mocha": "^3.4.2"
}
}
70 changes: 70 additions & 0 deletions test/test-fp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use strict';

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

describe('fp', () => {
describe('#map', () => {
it('should throw array not provided error', () => {
let mapArrErr = fp.map;
expect(mapArrErr).to.throw(Error);
});
it('should return an array with doubled numbers', () => {
let validMap = fp.map([1,2,3,4], (n) => { return n * 2; });
expect(validMap).to.be.an('array').that.includes.members([2,4,6,8]);
});
});
describe('#filter', () =>{
it('should throw array not provided error', () => {
let filterArrErr = fp.filter;
expect(filterArrErr).to.throw(Error);
});
it('should return an array that is missing the number 2', () => {
let validFilter = fp.filter([1, 2, 3, 4], (n) => { return n !== 2; });
expect(validFilter).to.be.an('array').to.not.have.members([2]);
});
});
describe('#concat', () => {
it('should throw an intial array not provided error', () => {
let concatArrErr = fp.concat;
expect(concatArrErr).to.throw(Error);
});
it('should be an array the is a combination of two arrays', () => {
let validConcat = fp.concat([1,2,3], [4,5,6]);
expect(validConcat).to.be.an('array').to.include.members([1,2,3,4,5,6]);
});
});
describe('#reduce', () =>{
it('should throw an intial array not provided error', () => {
let reduceArrErr = fp.concat;
expect(reduceArrErr).to.throw(Error);
});
it('should reduce an array down to a single value', () => {
let validReduce = fp.reduce([0, 1, 2, 3], (acc, n) => {return acc + n; }, 0);
expect(validReduce).to.equal(6);
});
it('should count amount of each name in an array and return it in an object', () => {
var names = ['Alice', 'Bob', 'Tiff', 'Bruce', 'Alice'];
var validNameReduce = fp.reduce(names, (allNames, name) => {
if (name in allNames) {
allNames[name]++;
}
else {
allNames[name] = 1;
}
return allNames;
}, {});
expect(validNameReduce).to.be.an('object');
});
});
describe('#splice', () => {
it('should throw an intial array not provided error', () =>{
let spliceArrErr = fp.concat;
expect(spliceArrErr).to.throw(Error);
});
it('should return [6,7,8]', () => {
let result = fp.splice([1,2,3,4,5,6,7,8], 5);
expect(result).to.be.an('array').to.include.members([6,7,8]);
});
});
});
24 changes: 24 additions & 0 deletions test/test-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const expect = require('chai').expect;
const main = require('../index.js');

describe('main', () => {var oldArgv = process.argv;
before(() => {
process.argv = [
'node path',
'file path',
'cat',
'dog',
];
});

after(() => {
process.argv = oldArgv;
});

it('should return \'CAT DOG\'', () => {
let result = main();
expect(result).to.be.a('string').to.have.string('CAT DOG');
});
});