Skip to content

[FE] Code challenge - Nguyen Ha Duy#266

Open
duyngha wants to merge 2 commits into
99techteam:mainfrom
duyngha:main
Open

[FE] Code challenge - Nguyen Ha Duy#266
duyngha wants to merge 2 commits into
99techteam:mainfrom
duyngha:main

Conversation

@duyngha
Copy link
Copy Markdown

@duyngha duyngha commented May 11, 2026

Summary

Solutions for code challenge problems 1–3.

  • Problem 1 — three sum_to_n(n) implementations
  • Problem 2 — currency swap form (Vite + React + TS + Tailwind)
  • Problem 3 — code review & refactor of the provided WalletPage

Problem 1 — sum_to_n

Three distinct implementations of sum_to_n(n) in src/problem1/index.js:

Function Approach Time Space
sum_to_n_a Iterative for loop O(n) O(1)
sum_to_n_b Closed-form n*(n+1)/2 O(1) O(1)
sum_to_n_c Recursion O(n) O(n)

Run:

node src/problem1/index.js

See src/problem1/README.md for tradeoffs.


Problem 2 — Currency Swap Form

image-swapping

A polished, Swap UI in src/problem2/.

Stack: Vite + React 19 + TypeScript + Tailwind CSS v4, with shadcn/ui.

Features:

  • Live token list and prices from interview.switcheo.com/prices.json (deduped; tokens without a positive price are omitted)
  • Searchable token combobox with keyboard navigation
  • Auto-computed exchange rate and USD subtotal
  • Swap-direction toggle (auto-swaps the pair if the user picks the same token on the opposite side)
  • Inline validation (empty / non-numeric / zero / same-token)
  • Skeleton while loading; retry button on fetch failure
  • Simulated submit with a 1.5s loading state and success message
  • Light/dark theme (toggle with d), responsive

Run:

cd src/problem2
npm install
npm run dev

Problem 3 — WalletPage Refactor

Code review and refactor of the provided snippet, in src/problem3/.

README.md documents 14 issues grouped by severity:

  • Bugs: undefined lhsPriority, inverted filter (<= 0), incomplete sort comparator, unused formattedBalances, missing blockchain field on WalletBalance
  • Performance: prices in wrong useMemo deps, getPriority redeclared per render, redundant iteration passes
  • Type safety: any on getPriority, lying FormattedWalletBalance cast, array index as key
  • Maintainability: redundant React.FC + props: Props, empty interface, unused children

WalletPage.tsx is a clean reference refactor: priority lookup map hoisted out of the component, two memos split by dependency (filter/sort uses only balances; format/USD uses prices), stable keys on currency, no any, no dead code.

This folder is intentionally not a runnable app — imports reference assumed host-app symbols (@mui/material, hooks, WalletRow). See the README for full details.

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