Created
October 6, 2017 18:51
-
-
Save donburks/6519b1c79fac1d6382a1c126d45f31e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add(2)(3); | |
// 5 | |
function add(x) { | |
return function(y) { | |
return x + y; | |
}; | |
} | |
console.log(add(2)(3)); //5 | |
var waitForLater = add(2); | |
//Wait for one bajillion years | |
console.log(waitForLater(3)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var mul = require('./multiply'); | |
list.forEach(mul.multiply); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var leftpad = require('left-pad'); | |
console.log(leftpad("kitten", 10, "-")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numbers = process.argv.slice(2); | |
var math = require('./mathLib'); | |
/*console.log("RANGE: ", math.range(Number(numbers[0]), Number(numbers[1]))); | |
console.log("FACTORIAL: ", math.factorial(Number(numbers[0]), Number(numbers[1]))); | |
*/ | |
var x = Number(numbers[0]); | |
var y = Number(numbers[1]); | |
console.log("RANGE: ", math.doMath(x, y, "range")); | |
console.log("FACTORIAL: ", math.doMath(x, y, "factorial")); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doStuff(x, y) { | |
console.log("Starting with " + x + " and " + y); | |
} | |
function range(x, y) { | |
doStuff(x, y); | |
if (x > y) { | |
return false; | |
} | |
var results = { range: [] }; | |
for (var i = x; i <= y; i++) { | |
results.range.push(i); | |
} | |
return results; | |
} | |
function factorial(x, y) { | |
doStuff(x, y); | |
var factorial = x; | |
for (var j = x; j <= y; j++) { | |
factorial *= j; | |
} | |
return factorial; | |
} | |
function doMath(x, y, operation) { | |
if (operation == "range") { | |
return range(x, y); | |
} else { | |
return factorial(x, y); | |
} | |
} | |
module.exports = { | |
doMath: doMath | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var num = 2; | |
function multiply(x) { | |
console.log(x * num); | |
} | |
module.exports = { | |
multiply: multiply | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "formatter", | |
"version": "1.0.0", | |
"description": "Demonstrating npm and package.json for the Oct 02, 2017 cohort", | |
"main": "formatter.js", | |
"directories": { | |
"test": "test" | |
}, | |
"dependencies": { | |
"left-pad": "^1.1.3" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "mocha" | |
}, | |
"keywords": [ | |
"left-pad", | |
"npm", | |
"demo" | |
], | |
"author": "Don Burks <[email protected]> (https://donburks.com)", | |
"license": "ISC" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var assert = require('assert'); | |
var math = require('../mathLib'); | |
describe("Range function", function() { | |
it("should return an array", function() { | |
var result = math.doMath(1, 5, "range"); | |
assert.equal(result.range instanceof Array, true); | |
}); | |
it ("should return an array from 1 to 5 when given parameters of 1 and 5", function() { | |
var result = math.doMath(1, 5, "range"); | |
assert.deepEqual(result.range, [1, 2, 3, 4, 5]); | |
}); | |
it("should fail if x is greater than y", function() { | |
var result = math.doMath(5, 1, "range"); | |
assert.equal(result, false); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment