Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. export const calculateNoteDispense: Function = (amount: string | null | undefined): Array<resultObject> | undefined => {
  2. if (!!amount) {
  3. try {
  4. amount = amount.trim();
  5. if (amount.length === 0) {
  6. return void 0;
  7. }
  8. let numericAmount: number = parseInt(amount, 10);
  9. if (isNaN(numericAmount)) {
  10. return void 0;
  11. }
  12. let tempCount: Array<number> = [];
  13. let resultArray: Array<resultObject> = [];
  14. denominations.forEach((note: number, index: number) => {
  15. if (numericAmount >= note) {
  16. tempCount[index] = Math.floor(numericAmount / note);
  17. numericAmount = numericAmount - (tempCount[index] * note);
  18. }
  19. });
  20. denominations.forEach((note: number, index: number) => {
  21. resultArray[index] = typeof tempCount[index] === "undefined" ? { count: 0, note } : { count: tempCount[index], note };
  22. });
  23.  
  24. return resultArray.reverse();
  25. } catch (err) {
  26. return void 0;
  27. }
  28. }
  29. return void 0;
  30. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement