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
  •  
  •  
  •  
42 changes: 39 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
# 99Tech Code Challenge #1 #
# 99Tech Code Challenge #1

Note that if you fork this repository, your responses may be publicly linked to this repo.
Please submit your application along with the solutions attached or linked.
Please submit your application along with the solutions attached or linked.

It is important that you minimally attempt the problems, even if you do not arrive at a working solution.

## Submission ##
## Submission

You can either provide a link to an online repository, attach the solution in your application, or whichever method you prefer.
We're cool as long as we can view your solution without any pain.

## Problem Descriptions

### Problem 1
In `src/problem1/index.js` you’ll find three implementations of the same algorithm – summing the first `n` natural numbers:

- **`sum_to_n_a`**: straightforward iterative loop accumulating the sum.
- **`sum_to_n_b`**: recursive version that adds `n` to the result of `sum_to_n_b(n-1)` (note the stack‑overflow warning for large `n`).
- **`sum_to_n_c`**: constant‑time formula using `n * (n + 1) / 2`.

Each variant demonstrates a different approach to solving the same mathematical problem and could be used to discuss performance and edge cases.

### Problem 2
This directory contains a working Vite‑powered React + TypeScript project, not just a boilerplate. Key points:

- **Configuration**: `tsconfig.json`, `tsconfig.node.json`, `.eslintrc.cjs`, and `vite.config.ts` are already set up for linting, type checking, and hot‑module reloading.
- **Dependencies** include `react`, `react-dom`, `axios`, `styled-components` along with TypeScript and ESLint tooling.
- **Structure**: under `src/` you’ll find a small swap‑UI application:
- Reusable components (`Button`, `Loading`, `TokenImage`, `SwapSection`, `SelectTokensModal`, `ConfirmSwapModal`)
- Pages (`SwapPage`) and styling helpers (`Flex.styled.ts`)
- Shared `constants`, `enums`, `types`, and utility scripts (e.g. `generateImportImages.js`)
- Asset management under `assets/img` with an importer script
- **Scripts**: `npm run dev` starts the dev server, `npm run build` compiles TypeScript and bundles via Vite, and there’s a helper `generateImageObject` script.

The application demonstrates a typical modern React stack with styled‑components and structured folder layout.

### Problem 3
Two versions of a wallet balance page are provided:

- **`Example.tsx`** – an initial implementation sketching out the component, priority logic, and a placeholder `Datasource` class.
- **`RefactorVersion.tsx`** – a refactored, more polished variant that adds type definitions, `makeStyles` for styling, and detailed comments about performance considerations.

Both versions use a custom hook `useWalletBalances` (imported but not shown) to retrieve balances, then fetch price data from `https://interview.switcheo.com/prices.json` via the `Datasource` class. Balances are filtered and sorted by blockchain priority and converted to `WalletRow` elements with formatted amounts and USD values. The refactor includes notes about memoization, avoiding redundant calculations, and key generation for list items.

This problem exercises React hooks, async data fetching, and basic optimization/documentation practices.
Empty file removed src/problem1/.keep
Empty file.
28 changes: 28 additions & 0 deletions src/problem1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Implementation 1: Iterative
// This implementation uses a simple iterative loop to calculate the summation.
function sum_to_n_a(n) {
let sum = 0;

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

return sum;
}

// Implementation 2: Recursive
// This implementation uses recursion to calculate the summation.
//Warning: When n is large, this implementation may cause a stack overflow error due to the large number of recursive calls.
function sum_to_n_b(n) {
if (n === 1) {
return 1;
} else {
return n + sum_to_n_b(n - 1);
}
}

// Implementation 3: Formula
// This implementation utilizes the formula for the summation of the first N natural numbers, which is n * (n + 1) / 2.
function sum_to_n_c(n) {
return (n * (n + 1)) / 2;
}
18 changes: 18 additions & 0 deletions src/problem2/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions src/problem2/.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?
30 changes: 30 additions & 0 deletions src/problem2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
38 changes: 12 additions & 26 deletions src/problem2/index.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
<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" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fancy Swap Form</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
32 changes: 32 additions & 0 deletions src/problem2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "problem2",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"generateImageObject": "node src/utils/generateImportImages.js"
},
"dependencies": {
"axios": "^1.6.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"styled-components": "^6.1.8"
},
"devDependencies": {
"@types/node": "^20.12.2",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"typescript": "^5.2.2",
"vite": "^5.2.0"
}
}
1 change: 1 addition & 0 deletions src/problem2/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file removed src/problem2/script.js
Empty file.
38 changes: 38 additions & 0 deletions src/problem2/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#root {
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
8 changes: 8 additions & 0 deletions src/problem2/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "./App.css";
import SwapPage from "./pages/SwapPage/SwapPage";

function App() {
return <SwapPage />;
}

export default App;
3 changes: 3 additions & 0 deletions src/problem2/src/assets/img/icons/arrow-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/problem2/src/assets/img/icons/chevron-down-black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/problem2/src/assets/img/icons/chevron-down-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/problem2/src/assets/img/icons/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/problem2/src/assets/img/icons/loading.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/problem2/src/assets/img/icons/search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading