Skip to content

Commit

Permalink
Enhancement: Refactor algorithm creation script for user-friendly sim…
Browse files Browse the repository at this point in the history
…plicity
  • Loading branch information
EliasAfara committed Oct 26, 2023
1 parent 1c52208 commit 28d115f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ To create new algorithm and test files, follow these steps:

1. Open your terminal and navigate to the root directory of the repository.

2. Use the following command to create a new algorithm and its corresponding test file. Replace `<category>`, `<algorithm.js>`, and `<algorithm.test.js>` with your desired values:
2. Use the following command to create a new algorithm and its corresponding test file. Replace `<category>`, `<algorithm>` with your desired values:

```bash
npm run create-algorithm <category> <algorithm.js> <algorithm.test.js>
npm run create-algorithm <category> <algorithm>
```

For example:

```bash
npm run create-algorithm Searching BinarySearch.js BinarySearch.test.js
npm run create-algorithm Searching BinarySearch
```

3. The script will create the specified algorithm and test files in the appropriate category folder.
Expand Down
25 changes: 12 additions & 13 deletions create_algorithm.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
#!/bin/bash

# Check if the correct number of arguments is provided
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <category> <algorithm.js> <algorithm.test.js>"
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <category> <algorithm>"
exit 1
fi

category="$1"
algorithm_js="$2"
algorithm_test_js="$3"
algorithm="$2"
category_path="${category}/tests"

# Create the category directory and the tests directory if they don't exist
mkdir -p "$category_path"

# Create the algorithm file
algorithm_file_path="${category}/${algorithm_js}"
touch "$algorithm_file_path"
echo "// Implement your algorithm here" > "$algorithm_file_path"
# Create the algorithm.js file
algorithm_js="${category}/${algorithm}.js"
touch "$algorithm_js"
echo "// Implement your algorithm here" > "$algorithm_js"

# Create the test file
test_file_path="${category_path}/${algorithm_test_js}"
touch "$test_file_path"
echo "// Implement tests for your algorithm here" > "$test_file_path"
# Create the algorithm.test.js file
algorithm_test_js="${category_path}/${algorithm}.test.js"
touch "$algorithm_test_js"
echo "// Implement tests for your algorithm here" > "$algorithm_test_js"

echo "Created $algorithm_file_path and $test_file_path"
echo "Created $algorithm_js and $algorithm_test_js"

0 comments on commit 28d115f

Please sign in to comment.