Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/problem_1/sum_to_n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

var sum_to_n_a = function(n) {
let sum = 0;
for (let i = 1; i <= n; i++) {
sum += i;
}
return sum;
};

var sum_to_n_b = function(n) {
if (n <= 0) {
return 0;
}
if (n === 1) {
return 1;
}
return n + sum_to_n_b(n - 1);
};

var sum_to_n_c = function(n) {
return (n * (n + 1)) / 2;
};

console.log("Testing sum_to_n_a:");
console.log("sum_to_n_a(5) =", sum_to_n_a(5)); // Expected: 15

console.log("\nTesting sum_to_n_b:");
console.log("sum_to_n_b(5) =", sum_to_n_b(5)); // Expected: 15

console.log("\nTesting sum_to_n_c:");
console.log("sum_to_n_c(5) =", sum_to_n_c(5)); // Expected: 15
24 changes: 24 additions & 0 deletions src/problem_2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
69 changes: 69 additions & 0 deletions src/problem_2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Currency Swap Form

A modern, interactive currency swap form built with React and Vite.

## Features

- 🎨 Beautiful, modern UI with gradient design
- 💱 Real-time exchange rate calculation
- 🔄 Token swap functionality
- ✅ Input validation and error handling
- 📱 Responsive design
- 🖼️ Token icons from Switcheo token-icons repository
- 💰 Live price data from Switcheo API

## Project Structure

```
problem_2/
├── src/
│ ├── components/
│ │ ├── CurrencySwapForm.jsx
│ │ └── CurrencySwapForm.css
│ ├── lib/
│ │ ├── api.js # API utilities for fetching prices
│ │ └── validation.js # Input validation utilities
│ ├── App.jsx
│ ├── App.css
│ └── main.jsx
├── package.json
├── vite.config.js
└── index.html
```

## Getting Started

1. Install dependencies:
```bash
npm install
```

2. Start the development server:
```bash
npm run dev
```

3. Build for production:
```bash
npm run build
```

## API Integration

- **Token Prices**: Fetched from `https://interview.switcheo.com/prices.json`
- **Token Icons**: Loaded from `https://raw.githubusercontent.com/Switcheo/token-icons/main/tokens/{TOKEN}.svg`

## Usage

1. Select a "From" token from the dropdown
2. Select a "To" token from the dropdown
3. Enter the amount you want to swap
4. The output amount is automatically calculated based on current exchange rates
5. Click the swap button (↕️) to swap the tokens
6. Click "Swap" to execute the transaction

## Technologies Used

- React 18
- Vite
- CSS3 (with modern features like gradients and animations)
13 changes: 13 additions & 0 deletions src/problem_2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Currency Swap</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions src/problem_2/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"jsx": "react-jsx",
"moduleResolution": "bundler",
"allowImportingTsExtensions": false,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"strict": false,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
Loading