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-rob/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
41 changes: 41 additions & 0 deletions lab-rob/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"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-rob/.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
9 changes: 9 additions & 0 deletions lab-rob/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"cSpell.words": [
"advanced",
"gitlens",
"messages",
"monokai",
"seti"
]
}
24 changes: 24 additions & 0 deletions lab-rob/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Code Fellows: Code 401d19: Full-Stack JavaScript
## Lab 01: Node Ecosystem
#### 11/27/17 - Robert Reed

### greet.js
greet.js exports a single function, creatively called `greet()`. The function has an arity of 1, expecting a single string as its argument.

If a non-string (or no argument) is provided to the function, `null` is returned.

If a single string is provided as argument, the function returns a concatenated version of the string with `hello <string>`.

If multiple strings are provided, the first string is used.

### arithmetic.js
arithmetic.js exports an object containing three methods.

#### `arithmetic.areNums(array)`
`arithmetic.areNums()` has an arity of one, and expects a single array as argument. If a non-array or no argument is given, the method will throw an error. If an array of length 0 is provided, it will return `false`. Otherwise, if the array contains only elements of type `number`, the function will return `true`. If the array contains _any_ non-numbers, the function will return `false`.

#### `arithmetic.add(num1, num2)`
`arithmetic.add()` has an arity of 2 and expects numbers. If both arguments given are numbers, the function returns their sum. If either or both of the arguments are not a number, the function will return `null`. This method makes use of the `arithmetic.areNums()` method to ensure valid arguments are given. If additional arguments are given, and one of those arguments is not a number, the function will return `null`.

#### `arithmetic.sub(num1, num2)`
`arithmetic.sub()` has an arity of 2 and expects numbers. If both arguments given are numbers, the function returns their difference, in the form `num1 - num2`. If either or both of the arguments are not a number, the function will return `null`. This method makes use of the `arithmetic.areNums()` method to ensure valid arguments are given. If additional arguments are given, and one of those arguments is not a number, the function will return `null`.
37 changes: 37 additions & 0 deletions lab-rob/__test__/arithmetic.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

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

describe('Helper functions should return a boolean.', () => {
test('areNums(arry) should return true if all elements in the array are numbers', () => {
expect(arithmetic.areNums([1, 2, 3])).toBeTruthy();
});

test('areNums(arry) should return false if any element in the array is not a number, or if the array is empty.', () => {
expect(arithmetic.areNums([1, 2, 'hey'])).toBeFalsy();
expect(arithmetic.areNums([])).toBeFalsy();
});
});

describe('add(num1, num2) method should take in two numbers and return their sum.', () => {
test('If two numbers are given as arguments, add(num1, num2) should return their sum.', () => {
expect(arithmetic.add(1, 9)).toBe(10);
expect(arithmetic.add(-9, 5.5)).toBeCloseTo(-3.5);
});

test('If either argument is not a number, add(num1, num2) should return null.', () => {
expect(arithmetic.add(1, 'a')).toBeNull();
});
});

describe('sub(num1, num2) should take in two numbers and return the first minus the second.', () => {
test('If either argument is not a number, sub(num1, num2) should return null.', () => {
expect(arithmetic.sub('k', '')).toBeNull();
expect(arithmetic.sub(5,'8')).toBeNull();
});

test('sub(num1, num2 should return the difference of the two numbers assuming they are both numbers.', () => {
expect(arithmetic.sub(3, 12)).toBe(-9);
expect(arithmetic.sub(4.7, 1.8)).toBeCloseTo(2.9);
});
});
14 changes: 14 additions & 0 deletions lab-rob/__test__/greet.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

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

describe('Testing functionality for greet.js.', () => {
test('When greet(name) is called with a valid string, it should return "hello <name>".', () => {
expect(greet('world')).toBe('hello world');
});

test('When greet(name) is called with anything other than a string it should return null.', () => {
expect(greet(87)).toBeNull();
expect(greet()).toBeNull();
});
});
17 changes: 17 additions & 0 deletions lab-rob/lib/arithmetic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const arithmetic = module.exports = {};

arithmetic.areNums = arry => {
for(let i = 0; i < arry.length; i++)
if(typeof arry[i] !== 'number') return false;
return arry.length > 0 ? true : false;
};

arithmetic.add = function (num1, num2) {
return arithmetic.areNums(arguments) ? num1 + num2 : null;
};

arithmetic.sub = function (num1, num2) {
return arithmetic.areNums(arguments) ? num1 - num2 : null;
};
5 changes: 5 additions & 0 deletions lab-rob/lib/greet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = name => {
return name && typeof name === 'string' ? `hello ${name}` : null;
};
Loading