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
1 change: 1 addition & 0 deletions lab-ron/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*/vendor/
35 changes: 35 additions & 0 deletions lab-ron/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"globals" : {
"rawData": true,
"app": true,
"Handlebars": true,
"page": true,
"$": true,
"marked": true,
"hljs": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {"impliedStrict": true}
},
"env": {
"browser": true,
"jquery": true,
"node": true,
"es6": true
},
"rules": {
"semi": [2, "always"],
"eqeqeq": ["error", "always"],
"no-template-curly-in-string": "error",
"no-console": "off",
"no-undefined": "off",
"indent": ["error", 2],
"quotes": ["warn", "single", {"allowTemplateLiterals": true}],
"no-multi-spaces": ["warn", {"exceptions": { "VariableDeclarator": true }}],
"no-trailing-spaces": "warn",
"new-cap": "warn",
"no-redeclare": ["error", { "builtinGlobals": true }]
}
}
68 changes: 68 additions & 0 deletions lab-ron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Created by https://www.gitignore.io/api/osx,linux,node,vim

### OSX ###
.DS_Store
.AppleDouble
.LSOverride

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


### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

### Vim ###
# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~

# auto-generated tag files
tags

###### Personal
.tern-project
44 changes: 44 additions & 0 deletions lab-ron/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 01 Node Ecosystem

Greet and Arithmetic are functions that facilitate adding or subtracting two numbers or greeting someone.

## how to use

Please remember to require `greet` and `arithmetic` from the `lib/` directory at the top of your `index.js`

### greet()
- takes in an argument as a string, and returns `hello + <string>`
- if argument is not a string or null it will return `null`

```
console.log(greet('world'));
console.log(greet(6));

>> hello world
>> null
```


### arithmetic.add()
- takes in only two numbers as it's arguments and returns the sum of the numbers
- if any argument is not a number it will return `null`

```
console.log(arithmetic.add(2, 3));
console.log(arithmetic.add('2', '3'));

>> 5
>> null
```

### arithmetic.sub()
- takes in only two numbers as it's arguments and returns the difference of the numbers
- if any argument is not a number it will return `null`

```
console.log(arithmetic.sub(9, 3));
console.log(arithmetic.sub('9', '3'));

>> 6
>> null
```
35 changes: 35 additions & 0 deletions lab-ron/__test__/arithmetic.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

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

// arithmetic.add()
test('arithmetic.add(5, 3) should return 8', () => {
let result = arithmetic.add(5, 3);
expect(result).toEqual(8);
});

test('arithmetic.add(5, "3") should return null', () => {
let result = arithmetic.add(5, '3');
expect(result).toEqual(null);
});

test('arithmetic.add("5", 3) should return null', () => {
let result = arithmetic.add('5', 3);
expect(result).toEqual(null);
});

// arithmetic.sub()
test('arithmetic.sub(5, 3) should return 2', () => {
let result = arithmetic.sub(5, 3);
expect(result).toEqual(2);
});

test('arithmetic.sub(5, "3") should return null', () => {
let result = arithmetic.sub(5, '3');
expect(result).toEqual(null);
});

test('arithmetic.sub("5", 3) should return null', () => {
let result = arithmetic.sub('5', 3);
expect(result).toEqual(null);
});
19 changes: 19 additions & 0 deletions lab-ron/__test__/greet.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

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

test('greet() should return null', () => {
let result = greet();
expect(result).toEqual(null);
});

test('greet(6) should return null', () => {
let result = greet(6);
expect(result).toEqual(null);
});

test('greet(\'ron\') should return "hello ron"', () => {
let result = greet('ron');
expect(result).toEqual('hello ron');
});

15 changes: 15 additions & 0 deletions lab-ron/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

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

console.log(greet());
console.log(greet('ron'));

console.log(arithmetic.add(1,2));
console.log(arithmetic.sub(1,2));

console.log(arithmetic.add(1,'2'));
console.log(arithmetic.sub('1',2));


20 changes: 20 additions & 0 deletions lab-ron/lib/arithmetic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const arithmetic = {};

arithmetic.add = (a, b) => {
if (typeof a === 'number' && typeof b === 'number')
return a + b;
else
return null;
};


arithmetic.sub = (a, b) => {
if (typeof a === 'number' && typeof b === 'number')
return a - b;
else
return null;
};

module.exports = arithmetic;
8 changes: 8 additions & 0 deletions lab-ron/lib/greet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = (name) => {
if (typeof name === 'string')
return `hello ${name}`;
else
return null;
};
23 changes: 23 additions & 0 deletions lab-ron/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "01-node-ecosystem",
"version": "1.0.0",
"description": "First lab of 401",
"main": "index.js",
"dependencies": {
"jest": "^21.0.2"
},
"devDependencies": {},
"scripts": {
"test": "jest --runInBand"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ronbarrantes/01-node-ecosystem.git"
},
"author": "Ron Barrantes",
"license": "MIT",
"bugs": {
"url": "https://github.com/ronbarrantes/01-node-ecosystem/issues"
},
"homepage": "https://github.com/ronbarrantes/01-node-ecosystem#readme"
}