Skip to content

Commit d21528c

Browse files
author
vitaly.basaraba
committed
Featured: interview questions
0 parents  commit d21528c

File tree

7 files changed

+369
-0
lines changed

7 files changed

+369
-0
lines changed

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Node.js
2+
node_modules/
3+
npm-debug.log
4+
yarn-debug.log
5+
yarn-error.log
6+
7+
# Logs
8+
logs/
9+
*.log
10+
*.log.*
11+
12+
# Dependency directories
13+
jspm_packages/
14+
15+
# Build directories
16+
build/
17+
18+
# Webpack
19+
/.webpack/
20+
21+
# SCSS and Sass files
22+
*.css.map
23+
*.scssc
24+
25+
# IDEs and Editors
26+
.vscode/
27+
.idea/
28+
*.sublime-workspace
29+
30+
# Operating system files
31+
.DS_Store
32+
Thumbs.db
33+
34+
# Package-lock.json or Yarn lock file
35+
package-lock.json
36+
yarn.lock

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.0.0

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Interview Questions CLI
2+
3+
Welcome to the **Interview Questions CLI**, a powerful tool designed for users learning JavaScript and practicing coding every day. This repository provides a collection of interview questions categorized by difficulty level, allowing you to learn and improve your skills anytime, directly from your terminal.
4+
5+
## Features
6+
7+
- **Daily Practice**: Access a curated set of JavaScript interview questions to sharpen your coding skills.
8+
- **Difficulty Levels**: Choose questions by difficulty—`junior`, `middle`, or `senior`—to match your skill level.
9+
- **Flexible Output**: Get questions in multiple formats:
10+
- `text` for direct display in the terminal.
11+
- `array` or `json` for use in your projects or further study.
12+
- **Randomized Selection**: Practice with random questions to simulate real-world scenarios.
13+
14+
## Installation
15+
16+
Ensure you have [Node.js](https://nodejs.org/) installed on your machine.
17+
18+
1. Clone the repository:
19+
```bash
20+
git clone https://github.com/fix2015/interview-questions.git
21+
```
22+
2. Navigate to the project directory:
23+
```bash
24+
cd interview-questions-cli
25+
```
26+
3. Install dependencies:
27+
```bash
28+
npm install
29+
```
30+
4. Make the CLI globally accessible (optional):
31+
```bash
32+
npm link
33+
```
34+
35+
## Usage
36+
37+
Run the CLI using the following command:
38+
39+
```bash
40+
node cli.js [options]
41+
```
42+
43+
### Options
44+
45+
| Option | Description | Example |
46+
|-----------------|---------------------------------------------------------------|----------------------------------------|
47+
| `--filter` | Filter questions by type (`all`, `top`). Default is `all`. | `--filter top` |
48+
| `--amount` | Number of questions to retrieve (for `top` filter). | `--amount 5` |
49+
| `--level` | Filter by difficulty level (`junior`, `middle`, `senior`). | `--level junior` |
50+
| `--format` | Output format (`text`, `array`, `json`). Default is `text`. | `--format json` |
51+
| `--verbose` | Enable verbose logging for debugging. | `--verbose` |
52+
53+
### Examples
54+
55+
- Retrieve all questions:
56+
```bash
57+
node cli.js --filter all
58+
```
59+
60+
- Get the top 5 junior-level questions in JSON format:
61+
```bash
62+
node cli.js --filter top --amount 5 --level junior --format json
63+
```
64+
65+
- Use verbose mode to debug:
66+
```bash
67+
node cli.js --verbose
68+
```
69+
70+
## Who is this for?
71+
72+
This repository is perfect for:
73+
74+
- **JavaScript learners**: Enhance your knowledge with targeted practice.
75+
- **Job seekers**: Prepare for interviews by tackling real-world coding problems.
76+
- **Developers**: Quickly access a JSON or array of questions for use in projects or mock tests.
77+
78+
## Connect with Me:
79+
- [LinkedIn - Vitalii Semianchuk](https://www.linkedin.com/in/vitalii-semianchuk-9812a786/)
80+
- [Telegram - @jsmentorfree](https://t.me/jsmentorfree) - We do a lot of free teaching on this channel! Join us to learn and grow in web development.
81+
- [Tiktok - @jsmentoring](https://www.tiktok.com/@jsmentoring) Everyday new videos
82+
83+
## License
84+
85+
MIT License
86+
Copyright (c) 2024 Vitalii Semianchuk
87+
88+
## License
89+
90+
This project is licensed under the MIT License. See the `LICENSE` file for details.

cli.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
const interviewQuestion = require('./index.js');
5+
const getThemArgs = require('get-them-args');
6+
7+
const args = getThemArgs(process.argv.slice(2));
8+
const verbose = args.verbose || false;
9+
const filter = args.top ? 'top' : args.filter || 'all';
10+
const amount = args.top || '';
11+
const level = args.level || '';
12+
const format = args.format || 'text';
13+
14+
const logHeader = (header) => console.log('\x1b[32m%s\x1b[0m', header);
15+
const logDivider = () => console.log('_________________________');
16+
const logExampleParams = () => {
17+
console.log("\x1b[32m%s\x1b[0m", "Params example:");
18+
console.log("--top ${amount}");
19+
console.log("--level ( junior | middle | senior )");
20+
console.log("--format ( text | array | json )");
21+
};
22+
23+
const displayQuestions = (result, format) => {
24+
switch (format) {
25+
case 'json':
26+
console.log(JSON.stringify(result));
27+
break;
28+
case 'array':
29+
console.log(result);
30+
break;
31+
default:
32+
result.forEach(({ title, url }) => {
33+
console.log('');
34+
logHeader(`Question: ${title}`);
35+
console.info(`Visit: ${url}`);
36+
logDivider();
37+
});
38+
}
39+
};
40+
41+
const main = async () => {
42+
try {
43+
logHeader('Question:');
44+
if (amount) console.log('Top -', amount);
45+
if (level) console.log('Level -', level);
46+
if (filter) console.log('Filter -', filter);
47+
console.log('');
48+
49+
const result = await interviewQuestion({ filter, amount, level, format });
50+
displayQuestions(result, format);
51+
52+
console.log('');
53+
logExampleParams();
54+
55+
if (verbose) console.log('Send questions');
56+
} catch (error) {
57+
if (verbose) console.error(`Could not send questions: ${error.message}`);
58+
}
59+
};
60+
61+
main();

index.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
5+
/**
6+
* Class representing an InterviewQuestion handler.
7+
*/
8+
class InterviewQuestion {
9+
/**
10+
* Creates an instance of InterviewQuestion.
11+
* @param {Object} ports - Dependencies or external resources required.
12+
* @param {Object} [options={}] - Configuration options.
13+
* @param {boolean} [options.verbose=false] - Enable verbose logging.
14+
*/
15+
constructor(ports, options = {}) {
16+
this.ports = ports;
17+
this.options = options;
18+
this.verbose = options.verbose || false;
19+
this.data = require(path.resolve(__dirname, 'question.json'));
20+
}
21+
22+
/**
23+
* Logs a message if verbose mode is enabled.
24+
* @param {string} message - The message to log.
25+
*/
26+
log(message) {
27+
if (this.verbose) {
28+
console.log(message);
29+
}
30+
}
31+
32+
/**
33+
* Executes the main functionality of filtering and retrieving questions.
34+
* @param {string} [filter='all'] - The filter type (e.g., 'all', 'top').
35+
* @param {number} [amount=0] - The number of questions to retrieve if filter is 'top'.
36+
* @param {string|null} [level=null] - The difficulty level of questions ('junior', 'middle', 'senior').
37+
* @returns {Promise<Array>} The filtered list of questions.
38+
* @throws {Error} If an invalid level or filter type is provided.
39+
*/
40+
async execute(filter = 'all', amount = 0, level = null) {
41+
let filteredData = this.data;
42+
43+
// Filter by level if provided
44+
if (level) {
45+
const validLevels = ['junior', 'middle', 'senior'];
46+
if (!validLevels.includes(level)) {
47+
throw new Error(`Invalid level: ${level}. Valid levels are: ${validLevels.join(', ')}`);
48+
}
49+
filteredData = filteredData.filter(item => item.level === level);
50+
}
51+
52+
switch (filter) {
53+
case 'all':
54+
return filteredData;
55+
case 'top':
56+
return this.getTopQuestions(amount, filteredData);
57+
default:
58+
throw new Error(`Invalid filter type: ${filter}`);
59+
}
60+
}
61+
62+
/**
63+
* Retrieves the top N questions from the dataset.
64+
* @param {number} amount - The number of questions to retrieve.
65+
* @param {Array} data - The dataset to retrieve questions from.
66+
* @returns {Array} The top N questions.
67+
* @throws {Error} If the amount is not a positive integer.
68+
*/
69+
getTopQuestions(amount, data) {
70+
if (!Number.isInteger(amount) || amount <= 0) {
71+
throw new Error('Amount must be a positive integer.');
72+
}
73+
74+
// Shuffle the data array
75+
const shuffledData = data.sort(() => 0.5 - Math.random());
76+
77+
// Return the top N questions from the shuffled array
78+
return shuffledData.slice(0, amount);
79+
}
80+
}
81+
82+
/**
83+
* Factory function to create and execute an InterviewQuestion instance.
84+
* @param {Object} [options={}] - Configuration options.
85+
* @param {string} [options.filter='all'] - The filter type (e.g., 'all', 'top').
86+
* @param {number} [options.amount=0] - The number of questions to retrieve if filter is 'top'.
87+
* @param {string|null} [options.level=null] - The difficulty level of questions ('junior', 'middle', 'senior').
88+
* @returns {Promise<Array>} The filtered list of questions.
89+
*/
90+
module.exports = async function (options = {}) {
91+
const interviewQuestion = new InterviewQuestion(options);
92+
const { filter = 'all', amount = 0, level = null } = options;
93+
return interviewQuestion.execute(filter, amount, level);
94+
};

package.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "interview-questions",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1"
7+
},
8+
"repository": {
9+
"type": "git",
10+
"url": "git+https://github.com/fix2015/interview-questions.git"
11+
},
12+
"bin": {
13+
"interview-questions": "cli.js"
14+
},
15+
"keywords": [
16+
"interview",
17+
"questions",
18+
"filter",
19+
"difficulty-level",
20+
"question-generator",
21+
"junior",
22+
"middle",
23+
"senior",
24+
"top-questions",
25+
"json",
26+
"array",
27+
"text",
28+
"cli",
29+
"command-line-tool",
30+
"nodejs",
31+
"javascript",
32+
"random-selection",
33+
"question-bank"
34+
],
35+
"author": "Semianchuk Vitalii",
36+
"license": "ISC",
37+
"bugs": {
38+
"url": "https://github.com/fix2015/interview-questions/issues"
39+
},
40+
"homepage": "https://github.com/fix2015/interview-questions#readme",
41+
"description": "A CLI tool for generating interview questions by difficulty level and quantity, with support for multiple output formats including text, JSON, and arrays.",
42+
"dependencies": {
43+
"get-them-args": "^1.3.2"
44+
}
45+
}

question.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"title": "What is IndexedDB",
4+
"url": "https://www.tiktok.com/@jsmentoring/photo/7448276165661314336",
5+
"level": "junior"
6+
},
7+
{
8+
"title": "What are the options in a cookie",
9+
"url": "https://www.tiktok.com/@jsmentoring/photo/7448261980567145761",
10+
"level": "junior"
11+
},
12+
{
13+
"title": "Differences between cookie, local storage and session storage",
14+
"url": "https://www.tiktok.com/@jsmentoring/photo/7448258461030173985",
15+
"level": "junior"
16+
},
17+
{
18+
"title": "How do you delete a cookie",
19+
"url": "https://www.tiktok.com/@jsmentoring/photo/7448236859966197025",
20+
"level": "middle"
21+
},
22+
{
23+
"title": "What is a post message",
24+
"url": "https://www.tiktok.com/@jsmentoring/photo/7448205399074934049",
25+
"level": "middle"
26+
},
27+
{
28+
"title": "What are closures",
29+
"url": "https://www.tiktok.com/@jsmentoring/photo/7447942704148811041",
30+
"level": "middle"
31+
},
32+
{
33+
"title": "What are modules",
34+
"url": "https://www.tiktok.com/@jsmentoring/photo/7447936859029654816",
35+
"level": "middle"
36+
},
37+
{
38+
"title": "What are classes in ES6",
39+
"url": "https://www.tiktok.com/@jsmentoring/photo/7447909741977685280",
40+
"level": "senior"
41+
}
42+
]

0 commit comments

Comments
 (0)