Created
March 4, 2015 23:15
-
-
Save vidul-nikolaev-petrov/ba74633eb64b12f88332 to your computer and use it in GitHub Desktop.
Arbitrage Check
This file contains 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
/** | |
* Check for arbitrage bet. | |
* | |
* @class Arbitrage | |
*/ | |
var Arbitrage = Arbitrage || {}; | |
var args = []; | |
process.argv.forEach( | |
function (value, index) { | |
if (index > 1) { | |
args.push(parseFloat(value)); | |
} | |
} | |
); | |
/** | |
* | |
* @method arbitrageCheck | |
* | |
* @param [name] {Array} Coefficients numbers | |
* for given bet. Should be two or more. | |
* | |
* @return {Number} Under or over 100. Under | |
* would mean arbitrage, over would mean no | |
* arbitrage. | |
* | |
* @example | |
* Arbitrage.arbitrageCheck(1.69, 4.50, 6.50); // 96.78 which means ~3.22% profit (100 - 96.78) | |
* | |
*/ | |
Arbitrage.arbitrageCheck = function () { | |
var total = 0; | |
[].forEach.call(arguments, | |
function (value, index) { | |
total += 1 / value; | |
} | |
); | |
return total * 100; | |
} | |
console.log(Arbitrage.arbitrageCheck.apply(null, args).toFixed(2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment