Problem Statement
You are tasked with creating a utility function computeAmount that allows chaining multiple calls to represent large monetary values in Indian numbering system units — crores, lacs, and thousands.
Each chained method should return the same object to allow method chaining, and finally, a value() method should return the computed total in rupees.
Requirements
- Support the following chained methods:
.crore(val)→ addsval * 10,000,000.lacs(val)→ addsval * 100,000.thousand(val)→ addsval * 1,000
- Allow multiple chained calls in any order.
- Calling
.value()should return the final computed total. - Each intermediate call must return the same chainable object.
Example
const total = computeAmount()
.lacs(15)
.crore(5)
.crore(2)
.lacs(20)
.thousand(45)
.crore(7)
.value();
console.log(total); // 1420045000
Explanation:
15 lacs = 1,500,000
5 crore = 50,000,000
2 crore = 20,000,000
20 lacs = 2,000,000
45 thousand = 45,000
7 crore = 70,000,000
-----------------------
Total = 1420045000
Constraints
- Input values (
val) will always be non-negative numbers. - Chained methods can be called in any order.