| Folder Name | Branch | Score | Coefficient |
|---|---|---|---|
| /ts-autocomplete-trie | ts-autocomplete-trie | 100 | 0.7 |
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:
const data = [
'java',
'javascript',
'python',
];
const autocomplete = createAutoComplete(data);
autocomplete('ja'); // returns [ 'java', 'javascript' ]
autocomplete('javas'); // returns [ 'javascript' ]
autocomplete('p'); // returns [ 'python' ]
index.ts file in the ts-autocomplete-trie folder must export the createAutoComplete function as follows:function createAutoComplete(data: string[]): (prefix: string) => string[] {}
export { createAutoComplete };
To work with TypeScript and build your JavaScript output, you should use Vite, a fast and modern build tool.
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.
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
...
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.
Prettier and ESLint Configuration
prettier for auto-formatting in package.json.strict rule enabled for TypeScript.
lint script in package.json should run ESLint checks.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.
TypeScript Usage and Functions
any type in TypeScript.Code Duplication and Magic Numbers
Bundling and Modular Architecture
Your Pull Request must include:
While working on this task, keep a developer’s diary. Write down the decisions you made, the approaches you considered, where you got stuck, and how you worked through it.
The diary is not graded. Its purpose is to help you understand your own work more deeply and to give your mentor a basis for a real conversation about the task.
The “Diary” folder can be placed in the root of the project.
Maximum Score: 100 points
| Criteria | Points |
|---|---|
The branch is named ts-autocomplete-trie |
1 |
| Commit messages follow RS School Git Convention | 1 |
The ts-autocomplete-trie folder exists |
1 |
The index.ts file exists in the correct folder |
1 |
The index.ts file exports the createAutoComplete function |
1 |
| The function is implemented using a Trie (Prefix Tree) class | 2 |
| The function passes all provided tests | 2 |
| The solution is well-structured, readable, and follows best practices | 1 |
| ESLint is configured for TypeScript, and there are no errors | 1 |
The TypeScript config includes "strict": true |
1 |
The .prettierrc.json file added |
1 |
The package.json file includes scripts: “build”, lint”, “prettier” |
1 |
| All dependencies added as dev dependencies | 1 |
| Pull Request description includes all required elements: | |
| Task URL is included in the PR | 1 |
| Screenshot of local test results is attached in the PR | 1 |
| Algorithm analysis (Big O) is provided in the PR description | 1 |
| Submission and Deadline Dates are included in the PR | 1 |
| Your self-check of the task’s completion using checkboxes is included in the PR | 1 |
| Penalty: | |
| Less than 3 commits in the PR | -4 |
| Commit after the deadline and before mentor review | -4 |
| The solution includes any comments | -10 |
| The solution includes console.log | -2 |
| Code is not fully covered with types | -10 |
| ESLint errors | -2 |
Use of the any type |
-20 |
After submitting the task, your mentor will ask 2–3 questions from the areas below. Answers account for ~80 points of the total score, so make sure you can explain the concepts in your own words — not just recite a definition.
"javascript" after "java" is already present."strict": true enable in tsconfig.json? Name at least three checks it turns on and why they matter.any type discouraged? What are safer alternatives (unknown, generics, union types)?createAutoComplete.interface and a type alias in TypeScript? When would you choose one over the other?class to model the Trie rather than a plain object or a set of functions?strict TypeScript ruleset add beyond the base rules?dependencies and devDependencies in package.json? Why should build tools go in devDependencies?