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
32 changes: 32 additions & 0 deletions src/problem1/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Problem 1: Three ways to sum to n

// Method 1: Using a for loop (iterative approach)
var sum_to_n_a = function(n) {
let sum = 0;
for (let i = 1; i <= n; i++) {
sum += i;
}
return sum;
};

// Method 2: Using the mathematical formula n * (n + 1) / 2
var sum_to_n_b = function(n) {
return (n * (n + 1)) / 2;
};

// Method 3: Using recursion
var sum_to_n_c = function(n) {
if (n <= 1) {
return n;
}
return n + sum_to_n_c(n - 1);
};

// Test cases
console.log('Testing sum_to_n_a(5):', sum_to_n_a(5)); // Expected: 15
console.log('Testing sum_to_n_b(5):', sum_to_n_b(5)); // Expected: 15
console.log('Testing sum_to_n_c(5):', sum_to_n_c(5)); // Expected: 15

console.log('\nTesting sum_to_n_a(10):', sum_to_n_a(10)); // Expected: 55
console.log('Testing sum_to_n_b(10):', sum_to_n_b(10)); // Expected: 55
console.log('Testing sum_to_n_c(10):', sum_to_n_c(10)); // Expected: 55
81 changes: 81 additions & 0 deletions src/problem2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Currency Swap Form - React + Vite

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

## Features

- ⚛️ **React 18** - Modern React with hooks
- ⚡ **Vite** - Lightning-fast HMR and optimized builds
- 💱 **Real-time conversion** - Live currency exchange rate calculations
- 🔄 **Bidirectional editing** - Edit either send or receive amount
- ✨ **Smooth animations** - Professional UI with smooth transitions
- ✅ **Input validation** - Real-time error messages and validation
- 📱 **Responsive design** - Works seamlessly on all device sizes
- 🎨 **Modern UI** - Beautiful gradient theme with intuitive interactions

## Getting Started

### Installation

```bash
npm install
```

### Development

Start the development server with hot module replacement:

```bash
npm run dev
```

The app will open automatically at `http://localhost:3000`

### Build

Create an optimized production build:

```bash
npm run build
```

### Preview

Preview the production build locally:

```bash
npm run preview
```

## Project Structure

```
problem2/
├── src/
│ ├── components/
│ │ ├── CurrencySwap.jsx # Main currency swap component
│ │ └── CurrencySwap.css # Component styles
│ ├── App.jsx # Root component
│ ├── App.css # App-level styles
│ └── main.jsx # Application entry point
├── index.html # HTML template
├── vite.config.js # Vite configuration
└── package.json # Project dependencies
```

## Technologies

- **React 18** - UI library with hooks
- **Vite** - Next generation frontend tooling
- **CSS3** - Animations and responsive design

## Supported Currencies

- USD - US Dollar
- EUR - Euro
- GBP - British Pound
- JPY - Japanese Yen
- AUD - Australian Dollar
- CAD - Canadian Dollar
- CHF - Swiss Franc
- CNY - Chinese Yuan
37 changes: 11 additions & 26 deletions src/problem2/index.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fancy Form</title>

<!-- You may add more stuff here -->
<link href="style.css" rel="stylesheet" />
</head>

<body>

<!-- You may reorganise the whole HTML, as long as your form achieves the same effect. -->
<form onsubmit="return !1">
<h5>Swap</h5>
<label for="input-amount">Amount to send</label>
<input id="input-amount" />

<label for="output-amount">Amount to receive</label>
<input id="output-amount" />

<button>CONFIRM SWAP</button>
</form>
<script src="script.js"></script>
</body>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Currency Swap - React + Vite</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
Loading