Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
organize code differently. matuzi style.
- Loading branch information
1 parent
edb45b9
commit 389126f
Showing
6 changed files
with
83 additions
and
40 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = function(prev, current, years) { | ||
var yrs = years || 1, | ||
growth, | ||
doubles = 0, | ||
doubleRate = .0, | ||
square = prev; | ||
|
||
if (yrs === 1) { | ||
growth = ((current-prev)/prev); | ||
square = prev * 2; | ||
while (prev < square) { | ||
doubles++; | ||
prev = prev + (prev * growth); | ||
if (prev/square > .85) { | ||
prev = square; | ||
} | ||
} | ||
return 72/doubles; | ||
} | ||
|
||
while (square < current) { | ||
doubles++; | ||
square = square * 2; | ||
} | ||
|
||
if (current/square < .85) { | ||
doubles--; | ||
if (doubles === 1 && yrs > 1) { | ||
yrs--; | ||
} | ||
} | ||
|
||
doubleRate = yrs/(doubles || 1); | ||
return 72/doubleRate; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Assumes costs are starting capital | ||
module.exports = function(capital, sales, costs) { | ||
return Math.floor(100 * (sales - costs)/capital); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,8 @@ | ||
var roic = require('./roic.js'), | ||
growth = require('./growth.js'); | ||
|
||
module.exports = { | ||
// Assumes costs are starting capital | ||
roic: function(capital, sales, costs) { | ||
return 100 * (sales - costs)/capital; | ||
}, | ||
|
||
growth: function(prev, current, years) { | ||
var yrs = years || 1, | ||
growth, | ||
doubles = 0, | ||
doubleRate = .0, | ||
square = prev; | ||
|
||
if (yrs === 1) { | ||
growth = ((current-prev)/prev); | ||
square = prev * 2; | ||
while (prev < square) { | ||
doubles++; | ||
prev = prev + (prev * growth); | ||
if (prev/square > .85) { | ||
prev = square; | ||
} | ||
} | ||
return 72/doubles; | ||
} | ||
|
||
while (square < current) { | ||
doubles++; | ||
square = square * 2; | ||
} | ||
|
||
if (current/square < .85) { | ||
doubles--; | ||
if (doubles === 1 && yrs > 1) { | ||
yrs--; | ||
} | ||
} | ||
|
||
doubleRate = yrs/(doubles || 1); | ||
return 72/doubleRate; | ||
} | ||
"roic": roic, | ||
"growth": growth | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var growth = require('../../lib/growth.js'), | ||
test = require('tap').test; | ||
/** | ||
test("Test growth calculation.", function(t) { | ||
var result = growth(50, 100, 20); | ||
t.equal(result, 160, "roic for da da da"); | ||
t.end(); | ||
}); | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/****************************************************** | ||
** Assumes costs are starting capital | ||
******************************************************* | ||
module.exports = function(capital, sales, costs) { | ||
return 100 * (sales - costs)/capital; | ||
}; | ||
*/ | ||
|
||
var roic = require('../../lib/roic.js'), | ||
test = require('tap').test; | ||
|
||
test("Test roic calculation.", function(t) { | ||
var result = roic(50, 100, 20); | ||
t.equal(result, 160, "roic for da da da"); | ||
t.end(); | ||
}); | ||
|
||
test("Test roic calculation with non-integers mixed in.", function(t) { | ||
var result = roic(50.01, 20.02, -.05); | ||
var expected = Math.floor(100 * (20.07 / 50.01)); | ||
t.equal(result, expected, "roic for non integers."); | ||
t.end(); | ||
}); | ||
|
||
test("Test roic calculation.", function(t) { | ||
var result = roic('50', '100', '20'); | ||
t.equal(result, 160, "roic for da da da"); | ||
t.end(); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
var calculator = require('../../lib/util.js'), | ||
test = require('tap').test; | ||
|
||
|
||
test("Test roic calculation.", function(t) { | ||
var result = calculator.roic(50, 100, 20); | ||
t.equal(result, 160, "roic for da da da"); | ||
t.end(); | ||
}); | ||
|