donburks
10/6/2017 - 6:51 PM

add.js

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);
  });
});
{
  "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 <don@donburks.com> (https://donburks.com)",
  "license": "ISC"
}
var num = 2;

function multiply(x) {
  console.log(x * num);
}

module.exports = {
  multiply: multiply
}
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
};
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"));

var leftpad = require('left-pad');

console.log(leftpad("kitten", 10, "-"));
var list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var mul = require('./multiply');

list.forEach(mul.multiply);
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));