epam-short-track

Task 5. Autocomplete (TypeScript + Trie)

Folder Name Branch Score Coefficient
/ts-autocomplete-trie ts-autocomplete-trie 100 0.7

Task Description

Implement the createAutoComplete function in TypeScript that efficiently returns all strings from a given array that start with a provided prefix.
Your solution must be implemented using a Prefix Tree (Trie) for optimal search performance. Use Class syntax to define the Trie structure and its methods.

Learn more about Trie:

Requirements

Example

const data = [
  'java',
  'javascript',
  'python',
];

const autocomplete = createAutoComplete(data);

autocomplete('ja'); // returns [ 'java', 'javascript' ]
autocomplete('javas'); // returns [ 'javascript' ]
autocomplete('p'); // returns [ 'python' ]

Implementation Details

function createAutoComplete(data: string[]): (prefix: string) => string[] {}

export { createAutoComplete };

Project Setup and Building JavaScript with Vite

To work with TypeScript and build your JavaScript output, you should use Vite, a fast and modern build tool.

1. Initialize the Project

If you haven’t already, create your project folder and initialize it:

npm create vite@latest ts-autocomplete-trie -- --template vanilla-ts
cd ts-autocomplete-trie
npm install

This will set up a Vite project with TypeScript support.

2. Project Structure

Place your solution in the ts-autocomplete-trie folder, and ensure your main code is in index.ts:

/ts-autocomplete-trie
  /index.ts
  /package.json
  /tsconfig.json
  ...

3. Build JavaScript Output

To compile your TypeScript code to JavaScript, use the Vite build command:

npm run build

The compiled JavaScript files will be output to the dist directory by default.

4. Running and Testing


Code Formatting and Linting 🎨🔍

Prettier and ESLint Configuration

You can use the settings from https://github.com/PoMaKoM/prettier-demo and watch the video https://youtu.be/OLKZBiqD4iU to better understand Prettier settings.

Code Quality and Structure

TypeScript Usage and Functions

Code Duplication and Magic Numbers

Bundling and Modular Architecture

Pull Request Requirements

Your Pull Request must include:


Mentor Checklist

Maximum Score: 100 points

Criteria Points
The branch is named ts-autocomplete-trie 2
Commit messages follow RS School Git Convention 5
The ts-autocomplete-trie folder exists 2
The index.ts file exists in the correct folder 2
The index.ts file exports the createAutoComplete function 2
The function is implemented using a Trie (Prefix Tree) class 20
The function passes all provided tests 20
The solution is well-structured, readable, and follows best practices 10
ESLint is configured for TypeScript, and there are no errors 5
The TypeScript config includes "strict": true 5
The .prettierrc.json file added 5
The package.json file includes scripts: “build”, lint”, “prettier” 5
All dependencies added as dev dependencies 5
   
Pull Request description includes all required elements:  
Task URL is included in the PR 2
Screenshot of local test results is attached in the PR 2
Algorithm analysis (Big O) is provided in the PR description 4
Submission and Deadline Dates are included in the PR 2
Your self-check of the task’s completion using checkboxes is included in the PR 2
   
Penalty:  
Less than 3 commits in the PR -20
Commit after the deadline and before mentor review -20
The solution includes any comments -50
The solution includes console.log -10
Code is not fully covered with types -50
ESLint errors -10
Use of the any type -100

Notes