Browse Source

Fixed final person owing itself microcents due to float leftover

master
BinHong Lee 6 years ago
parent
commit
7b91ad7f69
1 changed files with 4 additions and 4 deletions
  1. +4
    -4
      index.js

+ 4
- 4
index.js View File

@@ -77,8 +77,8 @@ app.post('/emailPaymentChain', function (req, res) {
res.json(emails)
})

// app.listen(5000)
app.listen(process.env.PORT)
app.listen(5000)
// app.listen(process.env.PORT)

function total (input) {
var total = 0
@@ -158,7 +158,7 @@ function paymentChain (users) {
function paymentNetwork (users, backup) {
var chain = []

while (chain.length < users.length && backup.length > 0) {
while (chain.length < users.length && backup.length > 1) {
if (backup.length > 0 && backup[0].amount === 0) {
backup.splice(0, 1)
} else if ((0 !== (backup.length - 1)) && (backup[0].amount === (backup[backup.length - 1].amount * -1))) {
@@ -176,7 +176,7 @@ function paymentNetwork (users, backup) {
}
}
if (backup.length > 0) {
if (backup.length > 1) {
return paymentChain(users)
} else {
return chain


Loading…
Cancel
Save