Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const calculateNoteDispense: Function = (amount: string | null | undefined): Array<resultObject> | undefined => {
- if (!!amount) {
- try {
- amount = amount.trim();
- if (amount.length === 0) {
- return void 0;
- }
- let numericAmount: number = parseInt(amount, 10);
- if (isNaN(numericAmount)) {
- return void 0;
- }
- let tempCount: Array<number> = [];
- let resultArray: Array<resultObject> = [];
- denominations.forEach((note: number, index: number) => {
- if (numericAmount >= note) {
- tempCount[index] = Math.floor(numericAmount / note);
- numericAmount = numericAmount - (tempCount[index] * note);
- }
- });
- denominations.forEach((note: number, index: number) => {
- resultArray[index] = typeof tempCount[index] === "undefined" ? { count: 0, note } : { count: tempCount[index], note };
- });
- return resultArray.reverse();
- } catch (err) {
- return void 0;
- }
- }
- return void 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement