Node modules
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
**/node_modules
|
**/node_modules
|
||||||
**/flow-typed
|
**/flow-typed
|
||||||
**/flow-coverage
|
**/flow-coverage
|
||||||
|
**/out
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
"prefer-const": "error"
|
"prefer-const": "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"eslintIgnore": ["**/out/*.js"],
|
||||||
"flow-coverage-report": {
|
"flow-coverage-report": {
|
||||||
"concurrentFiles": 1,
|
"concurrentFiles": 1,
|
||||||
"excludeGlob": ["node_modules/**"],
|
"excludeGlob": ["node_modules/**"],
|
||||||
|
|||||||
+7
-23
@@ -15,10 +15,7 @@
|
|||||||
"author": "Federico Kereki",
|
"author": "Federico Kereki",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"babel": {
|
"babel": {
|
||||||
"presets": [
|
"presets": ["env", "flow"]
|
||||||
"env",
|
|
||||||
"flow"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
@@ -31,34 +28,21 @@
|
|||||||
"node": true,
|
"node": true,
|
||||||
"es6": true
|
"es6": true
|
||||||
},
|
},
|
||||||
"extends": [
|
"extends": ["eslint:recommended", "plugin:flowtype/recommended"],
|
||||||
"eslint:recommended",
|
"plugins": ["babel", "flowtype"],
|
||||||
"plugin:flowtype/recommended"
|
|
||||||
],
|
|
||||||
"plugins": [
|
|
||||||
"babel",
|
|
||||||
"flowtype"
|
|
||||||
],
|
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-console": "off",
|
"no-console": "off",
|
||||||
"no-var": "error",
|
"no-var": "error",
|
||||||
"prefer-const": "error"
|
"prefer-const": "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"eslintIgnore": ["**/out/*.js"],
|
||||||
"flow-coverage-report": {
|
"flow-coverage-report": {
|
||||||
"concurrentFiles": 1,
|
"concurrentFiles": 1,
|
||||||
"excludeGlob": [
|
"excludeGlob": ["node_modules/**"],
|
||||||
"node_modules/**"
|
"includeGlob": ["src/**/*.js"],
|
||||||
],
|
|
||||||
"includeGlob": [
|
|
||||||
"src/**/*.js"
|
|
||||||
],
|
|
||||||
"threshold": 90,
|
"threshold": 90,
|
||||||
"type": [
|
"type": ["text", "html", "json"]
|
||||||
"text",
|
|
||||||
"html",
|
|
||||||
"json"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"tabWidth": 4,
|
"tabWidth": 4,
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/* @flow */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const RM = require("./roundmath.js");
|
||||||
|
const { multR, divR } = require("./roundmath.js");
|
||||||
|
|
||||||
|
console.log(RM.addR(12.348, 4.221)); // 16.57
|
||||||
|
console.log(multR(22.9, 12.4)); // 283.96
|
||||||
|
console.log(divR(22, 7)); // 3.14
|
||||||
|
|
||||||
|
console.log(RM.changeSign(0.07)); // error; RM.changeSign is not a function
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/* @flow */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const roundToCents = (x: number): number => Math.round(x * 100) / 100;
|
||||||
|
|
||||||
|
const changeSign = (x: number): number => -x;
|
||||||
|
|
||||||
|
const addR = (x: number, y: number): number => roundToCents(x + y);
|
||||||
|
|
||||||
|
const subR = (x: number, y: number) => addR(x, changeSign(y));
|
||||||
|
|
||||||
|
const multR = (x: number, y: number): number => roundToCents(x * y);
|
||||||
|
|
||||||
|
const divR = (x: number, y: number): number => {
|
||||||
|
if (y === 0) {
|
||||||
|
throw new Error("Divisor must be nonzero");
|
||||||
|
} else {
|
||||||
|
return roundToCents(x / y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
NOTES:
|
||||||
|
1. Exports are all together, at the end, per convention
|
||||||
|
2. roundToCents and changeSign are not exported, on purpose
|
||||||
|
*/
|
||||||
|
exports.addR = addR;
|
||||||
|
exports.subR = subR;
|
||||||
|
exports.multR = multR;
|
||||||
|
exports.divR = divR;
|
||||||
Reference in New Issue
Block a user