Skip to content

[FE] - submission: Problems 1, 2 and 3 (with tests and docs) - #296

Open
hieuctfe wants to merge 9 commits into
99techteam:mainfrom
hieuctfe:main
Open

[FE] - submission: Problems 1, 2 and 3 (with tests and docs)#296
hieuctfe wants to merge 9 commits into
99techteam:mainfrom
hieuctfe:main

Conversation

@hieuctfe

@hieuctfe hieuctfe commented Jul 25, 2026

Copy link
Copy Markdown

Frontend role submission for the 99Tech Code Challenge, covering Problems 1, 2 and 3. Each problem ships with clean code, documentation, and unit tests.

Problem 1: Three ways to sum to n (src/problem1/)

Three distinct implementations of sum_to_n:

  • sum_to_n_a: iterative loop, O(n) time / O(1) space
  • sum_to_n_b: closed-form Gauss, O(1), sign-aware to match the negative-n convention
  • sum_to_n_c: recursion, O(n) time / O(n) stack

Problem 2: Fancy Form (src/problem2/)

A currency swap form built with Vite, React, TypeScript and Tailwind CSS.

  • Live prices from interview.switcheo.com/prices.json (deduped, priced tokens only) with an offline fallback
  • Searchable token selectors with Switcheo icons and a graceful fallback
  • Live exchange rate, USD hints, swap-direction flip, MAX
  • Inline validation (empty, zero, negative, non-numeric, same token, exceeds balance)
  • Mocked backend: submit is disabled while invalid, then shows a spinner and a success toast

53 tests with Vitest and React Testing Library (utils, price hook, SwapForm, TokenSelect). npm run build passes.

Problem 3: Messy React (src/problem3/)

README.md documents the computational inefficiencies and anti-patterns (bugs, performance, type-safety, React smells) with fixes. Business logic is extracted into a pure, tested walletLogic.ts consumed by a thin refactored.tsx. 18 unit tests (Vitest) and a clean tsc --noEmit, including regression tests for the original bugs.

Running

  • P1: cd src/problem1 && node --test
  • P2: cd src/problem2 && npm install && npm test && npm run build
  • P3: cd src/problem3 && npm install && npm test && npm run typecheck

hieuctfe added 6 commits July 25, 2026 11:12
Searchable token selectors with Switcheo icons, live prices.json rates,
input validation, swap-direction flip, and a mocked loading->success submit.
Unit tests for swap/format utils and usePrices; component tests for
SwapForm validation/flip/submit and TokenSelect search.
@hieuctfe hieuctfe changed the title Frontend submission — Problems 1, 2 & 3 (with tests & docs) [FE] submission — Problems 1, 2 & 3 (with tests & docs) Jul 25, 2026
@hieuctfe hieuctfe changed the title [FE] submission — Problems 1, 2 & 3 (with tests & docs) Frontend submission: Problems 1, 2 and 3 (with tests and docs) Jul 25, 2026
hieuctfe added 2 commits July 25, 2026 14:01
MAX rounded the balance to 8 decimals with toFixed (round-to-nearest),
which could produce an amount just above the real balance and fail the
insufficient-balance check. Floor to 8 decimals instead, and add a
magnitude-scaled epsilon to the balance comparison. Adds a regression test.
P1: collapse to a single sum_to_n.mjs with an inline self-test; drop the
separate test file and package.json.
P2: add i18n (en/vi JSON catalogs) with a language switcher, a wallet hook,
and prices/swap services, each with tests; wire into App and form components.
P3: move refactored.tsx under src/ and update tsconfig.
@hieuctfe hieuctfe changed the title Frontend submission: Problems 1, 2 and 3 (with tests and docs) [FE] - submission: Problems 1, 2 and 3 (with tests and docs) Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant