[FE] - Code Challenge - Nguyen Huu Phuoc #133
Open
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.
🚀 Problem 1: Three Unique Implementations of Sum to N 🚀
Implementation explanation
1.
sum_to_n_a
- Iterative Approach (For Loop)Approach: Classic iterative solution using a for loop
Pros:
Cons:
2.
sum_to_n_b
- Mathematical Formula ApproachApproach: Direct calculation using the arithmetic series formula
n * (n + 1) / 2
Pros:
Cons:
3.
sum_to_n_c
- Recursive ApproachApproach: Recursive solution with base case
Pros:
Cons:
Input Validation & Edge Cases
Robust Input Validation
Your
valid_input()
function ensures:n % 1 !== 0
)Number.MAX_SAFE_INTEGER
Edge Case Handling
All implementations properly handle:
Test Coverage
Your test suite comprehensively covers:
🚀 Problem 2 🚀
Currency Swap Form
Project Overview
This is a React + TypeScript + Vite application that implements a currency swap form allowing users to exchange one cryptocurrency for another. The project demonstrates modern frontend development practices with a clean, responsive UI.
Tech Stack
Core Technologies
Implemented Features
1. Real-time Currency Data
https://interview.switcheo.com/prices.json
2. Interactive Swap Interface
/public/tokens/
3. Smart Calculations
4. State Management
fromCurrency
,toCurrency
, and swap operations5. User Experience
Strengths of Current Implementation
🚀 Problem 3🚀
Critical Issues
Undefined Variable Reference:
lhsPriority
is used but never defined (line in filter function). This will cause a runtime error.Incorrect Type Usage:
sortedBalances
is typed asWalletBalance[]
but used asFormattedWalletBalance[]
in the rows mapping.Missing
blockchain
Property: TheWalletBalance
interface lacks ablockchain
property that's used throughout the code.Performance Anti-patterns
Inefficient useMemo Dependencies: The
sortedBalances
useMemo includesprices
in dependencies but doesn't useprices
in the computation, causing unnecessary recalculations.Double Array Processing:
formattedBalances
is computed but never used, whilesortedBalances
is processed again in the rows mapping - wasteful double iteration.Missing Memoization:
formattedBalances
androws
aren't memoized, causing recalculation on every render.Inefficient Key Usage: Using array
index
as React key instead of a stable unique identifier can cause rendering issues and poor performance.Logic Issues
Inverted Filter Logic: The filter condition
if (lhsPriority > -99)
thenif (balance.amount <= 0) return true
keeps zero/negative balances, which is likely unintended.Incomplete Sort Comparison: The sort function doesn't handle the case where priorities are equal, potentially causing unstable sorting.
Any Type Usage:
getPriority
parameter usesany
type instead of a proper string type.Code Quality Issues
Empty Interface:
Props extends BoxProps
but adds nothing - could directly useBoxProps
.Redundant Destructuring:
(props: Props)
then immediate destructuring is verbose.Refactored Version
blockchain
property to WalletBalance interfaceformattedBalances
variable