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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 21 additions & 0 deletions src/problem1/REQUIREMENT.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Provide 3 unique implementations of the following function in JavaScript.

**Input**: `n` - any integer

_Assuming this input will always produce a result lesser than `Number.MAX_SAFE_INTEGER`_.

**Output**: `return` - summation to `n`, i.e. `sum_to_n(5) === 1 + 2 + 3 + 4 + 5 === 15`.

```jsx
var sum_to_n_a = function (n) {
// your code here
};

var sum_to_n_b = function (n) {
// your code here
};

var sum_to_n_c = function (n) {
// your code here
};
```
47 changes: 47 additions & 0 deletions src/problem1/SCRIPT.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Run TypeScript Solution

## Compile TypeScript to JavaScript

Run the following command:

```bash
npx tsc solution.ts
```

This will generate:

```bash
solution.js
```

---

## Run the JavaScript file

```bash
node solution.js
```

---

## Example Output

```bash
Iterative:
sum_to_n(1) = 1
sum_to_n(5) = 15
sum_to_n(10) = 55
sum_to_n(100) = 5050

Functional:
sum_to_n(1) = 1
sum_to_n(5) = 15
sum_to_n(10) = 55
sum_to_n(100) = 5050

Recursive:
sum_to_n(1) = 1
sum_to_n(5) = 15
sum_to_n(10) = 55
sum_to_n(100) = 5050
```
46 changes: 46 additions & 0 deletions src/problem1/solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Iterative
var sum_to_n_a = function (n: number) : number {
let sum = 0;

for (let i = 1; i <= n; i++) {
sum += i;
}

return sum;
};

// Functional (reduce)
var sum_to_n_b = function (n : number) : number {
return Array.from({ length: n }, (_, i) => i + 1).reduce(
(a, b) => a + b,
0
);
};

// Recursive
var sum_to_n_c = function (n: number) : number {
if(n === 1) return 1

return n + sum_to_n_c(n - 1);
};

// Test cases
function runTests() {
const testCases = [1, 5, 10, 100];

const functions = [
{ name: "Iterative", fn: sum_to_n_a },
{ name: "Functional", fn: sum_to_n_b },
{ name: "Recursive", fn: sum_to_n_c },
];

functions.forEach(({ name, fn }) => {
console.log(`\n${name}:`);

testCases.forEach((n) => {
console.log(`sum_to_n(${n}) = ${fn(n)}`);
});
});
}

runTests();
28 changes: 28 additions & 0 deletions src/problem2/fancy-form/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

yarn.lock
package-lock.json
.pnp.*

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

A modern currency swap interface built with React, TypeScript, and Vite.

The application allows users to:

- View available token balances
- Swap between different currencies
- Simulate swap transactions
- Experience smooth animations and responsive UI interactions

## Tech Stack

- React
- TypeScript
- Vite
- TailwindCSS
- Framer Motion
- Lucide React

## Features

- Token balance management
- Swap direction toggle
- Animated UI interactions
- Responsive design
- Mock transaction confirmation flow
- Dynamic token icons
- Loading states and validations

## API

Token prices are fetched from:

```txt
https://interview.switcheo.com/prices.json
```

Token icons are loaded from:

```txt
https://github.com/Switcheo/token-icons
```

---

# Getting Started

## Install dependencies

### Using npm

```bash
npm install
```

### Using yarn

```bash
yarn
```

---

# Run Development Server

### Using npm

```bash
npm run dev
```

### Using yarn

```bash
yarn dev
```

---

# Build Project

### Using npm

```bash
npm run build
```

### Using yarn

```bash
yarn build
```

---

# Preview Production Build

### Using npm

```bash
npm run preview
```

### Using yarn

```bash
yarn preview
```
21 changes: 21 additions & 0 deletions src/problem2/fancy-form/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config'

export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
globals: globals.browser,
},
},
])
16 changes: 16 additions & 0 deletions src/problem2/fancy-form/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>swap-app</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

</html>
43 changes: 43 additions & 0 deletions src/problem2/fancy-form/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "fancy-form",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@radix-ui/react-dialog": "^1.1.15",
"@radix-ui/react-dropdown-menu": "^2.1.16",
"@radix-ui/react-select": "^2.2.6",
"@radix-ui/react-slot": "^1.2.4",
"@radix-ui/react-tooltip": "^1.2.8",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"framer-motion": "^12.38.0",
"lucide-react": "^1.14.0",
"react": "^19.2.6",
"react-dom": "^19.2.6",
"tailwind-merge": "^3.6.0"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
"@types/node": "^24.12.3",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^6.0.1",
"autoprefixer": "^10.5.0",
"eslint": "^10.3.0",
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.5.2",
"globals": "^17.6.0",
"postcss": "^8.5.14",
"tailwindcss": "^3.4.19",
"typescript": "~6.0.2",
"typescript-eslint": "^8.59.2",
"vite": "^8.0.12"
}
}
6 changes: 6 additions & 0 deletions src/problem2/fancy-form/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
17 changes: 17 additions & 0 deletions src/problem2/fancy-form/public/assets/tokens/1INCH.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/problem2/fancy-form/public/assets/tokens/AAVE.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/problem2/fancy-form/public/assets/tokens/ACT.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading