Linh Ha (haconglinh1990@gmail.com) — Solutions for Problems 1, 2, 3#274
Open
haconglinh1990 wants to merge 21 commits into
Open
Linh Ha (haconglinh1990@gmail.com) — Solutions for Problems 1, 2, 3#274haconglinh1990 wants to merge 21 commits into
haconglinh1990 wants to merge 21 commits into
Conversation
Captures the brainstormed design for the fancy currency swap form: tech stack (Vite + React + TS + Tailwind + Headless UI + sonner + framer-motion), dark glassmorphism aesthetic, file structure, state machine with two-way binding rule, validation rules, mock submit flow, and a narrow unit-test plan. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
14 bite-sized tasks covering bootstrap, Tailwind theme, vitest setup, shared types and helpers, TDD for swap math/validation/usePrices/ useSwapReducer, then the seven components, and the App shell with loading + error + toast wiring. Each task ends with a commit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds iterative, closed-form (Gauss), and reduce-based implementations with complexity notes and a small self-check runner.
Preserves the original buggy component in Original.tsx for reference, documents 6 correctness bugs and TS/perf issues in README.md, and provides a cleaner WalletPage.tsx with hoisted priority table, decorate- sort-undecorate, split filter/format memos, and stable composite keys.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Submission by Linh Ha (@haconglinh1990) — three solved problems.
What's included
Problem 1 —
src/problem1/sum_to_n.jsThree implementations of
sum_to_n(n): iterativeO(n), closed-form GaussO(1), and a functional reduceO(n)/O(n). Each has complexity notes and handles negativensymmetrically. A small self-check runs when invoked asnode sum_to_n.js.Problem 2 —
src/problem2/A polished currency swap form built with Vite + React + TypeScript + Tailwind + Headless UI + framer-motion + sonner. Dark glassmorphism aesthetic. Live exchange rates from
https://interview.switcheo.com/prices.json(fetched once, deduped to latest entry per symbol, tokens without prices dropped). Searchable token picker, two-way amount binding, USD value display, flip-direction button, inline + on-blur validation, disabled submit with tooltip reason, mock 1.5 s submit with a success toast, loading skeleton and error-retry states. 61 unit tests cover the pure logic and the data hook.prefers-reduced-motionrespected.src/problem3/Refactor of the buggy
WalletPage.Original.tsxpreserves the original verbatim for reference;README.mddocuments six correctness bugs plus a list of TypeScript and performance issues;WalletPage.tsxis the cleaned-up version with a hoisted priority lookup, decorate-sort-undecorate, split filter/format memos with correct dependency arrays, and stable composite keys.Problems 4 and 5 are not attempted.
How to verify
Problem 1:
Problem 2:
A smoke-test walkthrough is in
src/problem2/README.md.Problem 3:
The refactor compiles in isolation only if the original project hooks (
useWalletBalances,usePrices,WalletRow,BoxProps,classes) are wired in — see the comment block at the top ofWalletPage.tsx.README.mdwalks through the issues one by one.Notes on the spec/plan trail
Design spec and step-by-step implementation plan for Problem 2 are committed under
docs/superpowers/specs/anddocs/superpowers/plans/so the reasoning behind the architecture and validation rules is auditable.