Skip to content

[FE]: Code challenge solution#226

Open
ScottQT wants to merge 4 commits into99techteam:mainfrom
ScottQT:feat/code-challenge-solutions
Open

[FE]: Code challenge solution#226
ScottQT wants to merge 4 commits into99techteam:mainfrom
ScottQT:feat/code-challenge-solutions

Conversation

@ScottQT
Copy link

@ScottQT ScottQT commented Mar 9, 2026

feat(problem1): sum 1 to n with 3 implementations and tests

  • Implement sum_to_n in three ways:
    A) Closed-form n(n+1)/2 — O(1) time and space.
    B) For-loop accumulation — O(n) time, O(1) space.
    C) Recursion with base case n<1 — O(n) time, O(n) stack.
  • Edge cases: n<1 returns 0; non-integer input truncated via Math.floor.
  • Add sum_to_n.test.js: normal cases (5, 1, 10, 100), n=0, negative n, non-integer.
  • Export for Node; all implementations pure and deterministic.

feat(problem2): currency swap form with Vite, React, TypeScript

  • Replace template with Vite + React; business logic in TypeScript, UI in JSX.
  • Data: Switcheo prices.json and token-icons repo; dedupe by currency (latest date), omit tokens without price.
  • Architecture: services (priceService), hooks (useTokensWithPrices, useSwapForm), utils (exchange, validation, tokenIcon, imagePreload), types (Token, PriceRecord).
  • UI: SwapCard, TokenSelect, TokenIcon; validation, swap direction button, live exchange rate, amount to receive read-only.
  • Preload token images on load for faster dropdown; fallback icon (first letter) when image fails.
  • Toast on swap success/error with details (amount from/to) in English; auto-dismiss and close button.
  • Run: cd src/problem2 && npm install && npm run dev

Forms UI

Screenshot 2026-03-09 at 19 09 09

feat(problem3): WalletPage analysis and refactor

  • ANALYSIS.md: document 14 issues — wrong filter variable (lhsPriority→balancePriority), inverted filter logic, missing blockchain on WalletBalance, unnecessary useMemo deps (prices), sort comparator missing return 0, formattedBalances unused and rows from wrong source, key={index}, getPriority recreated every render, any for blockchain, empty Props, logic in component, no error/loading handling, memoization — with fixes.
  • Refactor: types (wallet.ts, Blockchain union), utils (walletBalance.ts — priority, filter, sort, format), hook (useSortedFormattedBalances), WalletPage UI-only with stable keys and no business logic.
  • Aligns with separation of concerns, type safety, and performance practices.

- Add rules.md: senior engineering standards for the code challenge.
- Implement sum_to_n in three ways:
  A) Closed-form n(n+1)/2 — O(1) time/space.
  B) For-loop accumulation — O(n) time, O(1) space.
  C) Recursion with base case n<1 — O(n) time, O(n) stack.
- Handle edge cases: n<1 returns 0, non-integer via Math.floor.
- Add sum_to_n.test.js: normal cases, n=0, negative, non-integer.
- All logic pure; exports for Node.

Made-with: Cursor
- Replace template with Vite + React app; logic in TypeScript, UI in JSX.
- Data: Switcheo prices.json and token-icons repo; dedupe by currency, omit no-price.
- Architecture: services (priceService), hooks (useTokensWithPrices, useSwapForm),
  utils (exchange, validation, tokenIcon, imagePreload), types (Token, PriceRecord).
- UI: SwapCard, TokenSelect, TokenIcon; validation, swap direction, rate display.
- Preload token images on load; fallback icon on image error; toast on success/error
  with swap details (amount from/to). English toast messages.

Made-with: Cursor
- ANALYSIS.md: document 14 issues (bugs, performance, types, architecture).
  Fix wrong filter variable (lhsPriority→balancePriority), filter logic,
  missing blockchain on WalletBalance, useMemo deps, sort return 0,
  use formattedBalances for rows, stable keys, getPriority outside component,
  Blockchain union type, logic in hook/utils, error/loading handling.
- Refactor: types (wallet.ts), utils (walletBalance.ts), hook
  (useSortedFormattedBalances), WalletPage UI-only. Aligns with rules.md.

Made-with: Cursor
Made-with: Cursor
@ScottQT ScottQT changed the title Feat/code challenge solutions Featcode challenge solutions Mar 9, 2026
@ScottQT ScottQT changed the title Featcode challenge solutions [FE]: Code challenge solution Mar 9, 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.

2 participants