Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented "allocate" function, as described by Martin Fowler #1

Merged
merged 2 commits into from
Feb 27, 2014

Conversation

renatoargh
Copy link
Contributor

Hi @demchenkoe,

This pull request adds the feature of allocation. It is basically a way to "divide" money without loosing cents, and it is described by Martin Fowler in his book "Patterns of Enterprise Application Architecture" and here.

An example of how it works:

Basic Functionality

var amountDue = new Money(100),
    payments = amountDue.allocate(3); 

//payments is now an array whose sum equals to 100 USD
payments.forEach(function(payment) {
    //will print; $33.33, then $33.33, then $33.34 
    console.log(payment.format()); 
});

Applying different ratios

var amountDue = new Money(123),
    //this means three payments of 25%, 50% and 25%
    payments = amountDue.allocate([1, 2, 1]); 

//payments is now an array whose sum equals to 123 USD
payments.forEach(function(payment) {
    //will print; $30.75, then $61.50, then $30.75 
    console.log(payment.format()); 
});

Also I have added my name as contributor at package.json and have bumped the version to v0.0.2 in case you find this cool enough to merge.

Thank you for the cool module!

@@ -1,2 +1,7 @@
.idea
node_modules

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring eclipse IDE project files

demchenkoe added a commit that referenced this pull request Feb 27, 2014
Implemented "allocate" function, as described by Martin Fowler
@demchenkoe demchenkoe merged commit 95a80c3 into demchenkoe:master Feb 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants