sgtpep / test-load-funds

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

test-load-funds CI

A program that accepts or declines attempts to load funds into customers' accounts based on the following limits:

  • A maximum of $5,000 can be loaded per day.
  • A maximum of $20,000 can be loaded per week.
  • A maximum of 3 loads can be performed per day, regardless of the amount.

Installation

git clone https://github.com/sgtpep/test-load-funds.git
cd test-load-funds
npm i

Usage

Process loads line-by-line from input.txt (by default) and output results to stdout:

./load-funds

Process loads line-by-line from input-file and output results to stdout:

./load-funds input-file

Process loads line-by-line from input-file and write results to output-file:

./load-funds input-file output-file

Scripts

  • npm run typecheck — Perform type checking.
  • npm run lint — Run lint checks.
  • npm run format — Format code.
  • npm run test — Run tests.
  • npm run check — Run all the above scripts.

Comments

  • ./src/loadFunds.ts is an entry point to the script.
  • An experimental ESM-compatible ts-node script is used to run TypeScript code directly transpiling it in-memory.
  • Complexity: O(1) time; O(1) (best case) and O(n) (worst case) space, because of previously observed item ids stored in-memory.
  • Added nominal types to some primitive values (like ids, amounts, etc.) to distinguish them from basic types. See https://basarat.gitbook.io/typescript/main-1/nominaltyping, microsoft/TypeScript#202 for details.
  • Functions isSameDay and isSameISOWeek from date-fns package could be used to simplify dealing with dates.

About


Languages

Language:TypeScript 99.8%Language:Shell 0.2%