Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahtrahdis7/node-splitwise-js
Minimize Cash Flow among a given set of friends who have borrowed money from each other using JavaScript. [200+ NPM Downloads]
https://github.com/ahtrahdis7/node-splitwise-js
algorithm greedy javascript low-level-design nodejs split splitwise splitwize
Last synced: about 2 months ago
JSON representation
Minimize Cash Flow among a given set of friends who have borrowed money from each other using JavaScript. [200+ NPM Downloads]
- Host: GitHub
- URL: https://github.com/ahtrahdis7/node-splitwise-js
- Owner: ahtrahdis7
- Created: 2021-07-01T12:28:04.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-27T17:26:40.000Z (about 1 year ago)
- Last Synced: 2024-02-22T22:46:48.526Z (11 months ago)
- Topics: algorithm, greedy, javascript, low-level-design, nodejs, split, splitwise, splitwize
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/splitwise-js-map
- Size: 16.6 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Splitwise: Minimize Cash Flow Algorithm
Minimize Cash Flow among a given set of friends who have borrowed money from each other.
Given a number of friends who have to give or take some amount of money from one another. Design an algorithm by which the total cash flow among all the friends is minimized.### Approach :
Greedy.
Settle the debts of the people with Max and Min. Credits.### Data Structure Used :
1. Array : To storr the final outputs.
2. Map : To store and get remaining individual transaction amounts in O(1) time complexity.### Implementation :
npm install splitwise-js-map
const Splitwise = require('splitwise-js-map');var input = [
{
'paidBy': 'A',
'paidFor': { 'B': 300, 'C': 40, 'D': 30 }
},
{
'paidBy': 'B',
'paidFor': { 'A': 50, 'B': 100, 'C': 200 }
}
]const splits = Splitwise(input);
console.log(splits);
Output: [ `from`, `to` , `value`]
[ [ 'C', 'A', 240 ], [ 'B', 'A', 50 ], [ 'D', 'A', 30 ] ]### Updates :
Feel free to submit PRs for any improvements that you find.> !! HAPPY CODING !!