An open API service indexing awesome lists of open source software.

https://github.com/gah-code/leetcode-practice

A structured JavaScript practice environment for solving LeetCode problems efficiently with ESLint, Jest, and Quokka.js.
https://github.com/gah-code/leetcode-practice

exercises javascript jest leetcode

Last synced: 9 months ago
JSON representation

A structured JavaScript practice environment for solving LeetCode problems efficiently with ESLint, Jest, and Quokka.js.

Awesome Lists containing this project

README

          

# ๐Ÿš€ LeetCode JavaScript Practice

A structured JavaScript practice environment for solving **LeetCode problems** efficiently with **ESLint, Jest, and Quokka.js**.

## ๐Ÿ“Œ Project Overview

This project is designed to **streamline problem-solving in JavaScript** by integrating:

- **ESLint** for code quality and best practices.
- **Jest** for testing solutions automatically.
- **Quokka.js** for real-time execution and debugging.
- **Automated script** for quickly creating new problems.

---

## ๐Ÿ› ๏ธ Project Setup

### 1๏ธโƒฃ **Clone the Repository**

```sh
git clone https://github.com/gah-code/leetcode-practice.git
cd leetcode-practice
```

### 2๏ธโƒฃ **Install Dependencies**

```sh
npm install
```

### 3๏ธโƒฃ **Setup ESLint for Linting**

```sh
npx eslint --init
```

๐Ÿ”น **Custom ESLint Config** (`eslint.config.mjs`) is already set up to support Jest and Quokka.js.

---

## ๐Ÿงช Testing with Jest

Run all tests:

```sh
npm test
```

Run tests for a specific file:

```sh
npm test problems/fetch-with-retry.test.js
```

---

## โšก Using Quokka.js for Live Debugging

### **Installation**

1. Open **VS Code**.
2. Press **Cmd + Shift + X** (Mac) or **Ctrl + Shift + X** (Windows/Linux).
3. Search for **"Quokka.js"** and install the extension.

### **Quokka.js Commands**

| Command | Description |
|---------|-------------|
| `Cmd + Shift + P` โ†’ "Quokka.js: Start on Current File" | Runs Quokka in the open file |
| `Cmd + Shift + P` โ†’ "Quokka.js: Start on Current Project" | Runs Quokka for all configured files |
| `Cmd + K Q` | Stops Quokka |
| `Cmd + Shift + P` โ†’ "Quokka.js: Toggle Value Display" | Shows inline execution results |

---

## ๐Ÿ“‚ Folder Structure

```
leetcode-practice/
โ”‚โ”€โ”€ .quokka/ # Quokka.js config
โ”‚โ”€โ”€ problems/ # LeetCode problems
โ”‚ โ”œโ”€โ”€ fetch-with-retry.js # Example problem solution
โ”‚ โ”œโ”€โ”€ fetch-with-retry.test.js # Jest test for the problem
โ”‚โ”€โ”€ eslint.config.mjs # ESLint flat config setup
โ”‚โ”€โ”€ package.json # Project dependencies
โ”‚โ”€โ”€ problem-template.js # Template for new problems
โ”‚โ”€โ”€ new-problem.sh # Automation script for creating new problems
โ”‚โ”€โ”€ README.md # Project documentation
```

---

## ๐Ÿš€ Workflow: How to Add a New Problem

1๏ธโƒฃ **Create a New Problem File**
Run the following script:

```sh
./new-problem.sh fetch-with-retry
```

This will:

- Create a new problem file inside `problems/`
- Pre-fill the file with the standard **problem template**
- Open it automatically in **VS Code**

2๏ธโƒฃ **Implement the Solution**

- Write the function inside the newly created `.js` file.
- Use **Quokka.js** for real-time debugging.

3๏ธโƒฃ **Write Tests**

- Create a test file in `problems/` (if not generated automatically).
- Use **Jest** to write test cases.

4๏ธโƒฃ **Run Tests**

```sh
npm test
```

- Verify the solution with Jest before submitting.

---

## โœ… To-Do List & Future Enhancements V 1.1.0

- [ ] **Auto-generate Jest test files** when creating new problems.
- [ ] **Integrate Prettier** for automatic code formatting.
- [ ] **Improve error handling** for the `new-problem.sh` script.

---

## โœ… To-Do List & Future Enhancements V 1.2.0

- [ ] **Add TypeScript support** for stronger typing in solutions.
- [ ] **Implement GitHub Actions** for continuous integration.
- [ ] **Create a VS Code snippet extension** for inserting the problem template easily.

---

## ๐Ÿ“ Recommendations for Best Learning Experience

โœ… **Follow a structured approach:** Start with an easy problem, read the description carefully, implement, and test.
โœ… **Use Quokka.js:** Debug functions before running full Jest tests.
โœ… **Write detailed solution approaches:** Add comments to document thought processes.
โœ… **Refactor frequently:** Aim for clean, efficient, and readable code.
โœ… **Keep the repo organized:** Each problem should have a corresponding test file.

---

## ๐Ÿ’ก Have Suggestions?

Feel free to **contribute** or open an **issue** if youโ€™d like to see additional features! ๐Ÿš€

---