commit 111a00f45d021be7a113fb7ff513272aaabfdd13 Author: Abhas Date: Tue Dec 4 14:04:37 2018 +0530 Basic files diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5ebc552 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# EditorConfig is awesome: http://EditorConfig.org + +root = true; + +[*] +# Ensure there's no lingering whitespace +trim_trailing_whitespace = true +# Ensure a newline at the end of each file +insert_final_newline = true + +[*.js] +# Unix-style newlines +end_of_line = lf +charset = utf-8 +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..23bca43 --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Commenting this out is preferred by some people, see +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- +node_modules +bower_components +.nyc_output +coverage +tmp +docs + +# Users Environment Variables +.lock-wscript + +# Editors +.idea diff --git a/package.json b/package.json new file mode 100644 index 0000000..ba4d427 --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "name": "demo", + "version": "0.0.1", + "main": "src/index.js", + "scripts": { + + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..476c4ba --- /dev/null +++ b/src/index.js @@ -0,0 +1,3 @@ +const SIPCalculations = require('./sip'); + +module.exports = SIPCalculations; diff --git a/src/sip.js b/src/sip.js new file mode 100644 index 0000000..bcd4182 --- /dev/null +++ b/src/sip.js @@ -0,0 +1,32 @@ +// @ts-check + +const Calculations = { + + /** + * @description Get minimum SIP amount + * @returns {number} - Returns here + * @param {Array} priceArray - Input here + */ + getMaxAmount(priceArray) { + const maxPrice = Math.max(...priceArray); + return maxPrice; + }, + + /** + * Get total value of the order from order config + * @returns {number} - Output A + * @param {import('./types').OrderConfig} orderConfig - Input A + * @param {import('./types').SidPriceMap} sidPriceMap - Input B + */ + calculateOrderTotalValue: function calculateOrderTotalValue(orderConfig, sidPriceMap) { + const totalValue = orderConfig.reduce((prevValue, eachSidConfig) => { + const sidPrice = sidPriceMap[eachSidConfig.sid]; + const currentConfigValue = sidPrice * eachSidConfig.shares; + return (prevValue + currentConfigValue); + }, 0); + + return totalValue; + } +}; + +module.exports = Calculations; diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..e337501 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,12 @@ +export type sid = string; + +export interface OrderConfigElement { + sid: sid; + shares: number, +} + +export type OrderConfig = Array; + +export interface SidPriceMap { + [sid: string]: number; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..472dd1e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "module": "commonjs", + "allowJs": true + }, + "include": [ + "src/**/*" + ], + "exclude": [ + "node_modules" + ] +}