currency-breakdown 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +21 -0
  2. package/index.js +22 -0
  3. package/package.json +20 -0
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # currency-breakdown
2
+
3
+ Break an amount into currency denominations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install currency-breakdown
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```javascript
14
+ const breakdown = require("currency-breakdown");
15
+
16
+ console.log(breakdown(900));
17
+ // [500, 200, 200]
18
+
19
+ console.log(breakdown(43));
20
+ // [20, 20, 2, 1]
21
+ ```
package/index.js ADDED
@@ -0,0 +1,22 @@
1
+ const defaultCurrency = [500, 200, 100, 50, 20, 10, 5, 2, 1, 0.5, 0.25];
2
+
3
+ function breakdown(amount, currency = defaultCurrency) {
4
+ const result = {};
5
+
6
+ for (const note of currency) {
7
+ let count = 0;
8
+
9
+ while (amount >= note) {
10
+ amount = +(amount - note).toFixed(2);
11
+ count++;
12
+ }
13
+
14
+ if (count > 0) {
15
+ result[note] = count;
16
+ }
17
+ }
18
+
19
+ return result;
20
+ }
21
+
22
+ module.exports = breakdown;
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "currency-breakdown",
3
+ "version": "1.0.0",
4
+ "description": "Break amount into currency denominations",
5
+ "license": "ISC",
6
+ "author": "Rishiraj Bhanji",
7
+ "type": "commonjs",
8
+ "main": "index.js",
9
+ "keywords": [
10
+ "currency",
11
+ "money",
12
+ "denomination",
13
+ "cash",
14
+ "finance",
15
+ "indian-currency"
16
+ ],
17
+ "scripts": {
18
+ "test": "echo \"Error: no test specified\" && exit 1"
19
+ }
20
+ }