Skip to content

Commit 34e7128

Browse files
authored
Merge pull request #448 from sir-gon/develop
[DOC] Better README.
2 parents c210c62 + 764a2e6 commit 34e7128

File tree

1 file changed

+178
-66
lines changed

1 file changed

+178
-66
lines changed

README.md

+178-66
Original file line numberDiff line numberDiff line change
@@ -16,146 +16,258 @@
1616
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-js&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-js)
1717
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-js&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-js)
1818

19+
## TL;DR
20+
21+
[Install and run](#install-and-run)
22+
1923
## What is this?
2024

21-
[Project Euler](https://projecteuler.net/) provide some algorithms and mathematical
22-
problems to solve to be used as experience tests.
25+
This repository is part of a series that share and solve the same [objectives](#objetives),
26+
with the difference that each one is based on a different software ecosystem,
27+
depending on the chosen programming language:
2328

24-
Use this answers to learn some tip and tricks for algorithms tests.
29+
- [Modern Javascript: algorithm-exercises-js](https://github.com/sir-gon/algorithm-exercises-js)
30+
- [Python 3.x: algorithm-exercises-py](https://github.com/sir-gon/algorithm-exercises-py)
31+
- [Typescript: algorithm-exercises-ts](https://github.com/sir-gon/algorithm-exercises-ts)
32+
- [Go / Golang: algorithm-exercises-go](https://github.com/sir-gon/algorithm-exercises-go)
33+
- [Java: algorithm-exercises-java](https://github.com/sir-gon/algorithm-exercises-java)
34+
- [.NET / C#: algorithm-exercises-csharp](https://github.com/sir-gon/algorithm-exercises-csharp)
2535

26-
## Why I publish solutions?
36+
## Objetives
2737

28-
As Project Euler says:
38+
### Functional
2939

30-
<https://projecteuler.net/about#publish>
40+
- For academic purposes, it is an backup of some algorithm exercises
41+
(with their solutions), proposed by various sources:
42+
[leetcode, hackerrank, projecteuler](#algorithm-excersices-sources), ...
3143

32-
```text
33-
I learned so much solving problem XXX, so is it okay to publish my solution elsewhere?
34-
It appears that you have answered your own question. There is nothing quite like that "Aha!" moment when you finally beat a problem which you have been working on for some time. It is often through the best of intentions in wishing to share our insights so that others can enjoy that moment too. Sadly, that will rarely be the case for your readers. Real learning is an active process and seeing how it is done is a long way from experiencing that epiphany of discovery. Please do not deny others what you have so richly valued yourself.
44+
- The solutions must be written on "vanilla code", that is,
45+
avoiding as much as possible the use of external libraries (in runtime).
3546

36-
However, the rule about sharing solutions outside of Project Euler does not apply to the first one-hundred problems, as long as any discussion clearly aims to instruct methods, not just provide answers, and does not directly threaten to undermine the enjoyment of solving later problems. Problems 1 to 100 provide a wealth of helpful introductory teaching material and if you are able to respect our requirements, then we give permission for those problems and their solutions to be discussed elsewhere.
37-
```
47+
- Adoption of methodology and good practices.
48+
Each exercise is implemented as a unit test set,
49+
using TDD (Test-driven Development) and Clean Code ideas.
3850

39-
If you have better answers or optimal solutions, fork and PR-me
51+
### Technical
4052

41-
Enjoy 😁 !
53+
Foundation of a project that supports:
4254

43-
## Using NodeJS runtime
55+
- Explicit **typing** when the language supports it, even when it is not mandatory.
56+
- Static Code Analysis (**Lint**) of code, scripts and documentation.
57+
- Uniform **Code Styling**.
58+
- **Unit Test** framework.
59+
- **Coverge** collection. High coverage percentage. Equal or close to 100%.
60+
- **Pipeline** (Github Actions). Each command must take care of its
61+
return status code.
62+
- **Docker**-based workflow to replicate behavior in any environment.
63+
- Other tools to support the reinforcement of software development **good practices**.
4464

45-
### Requirements
65+
## Install and Run
4666

47-
You must install dependencies:
67+
You can run tests in the following ways:
4868

49-
```text
50-
npm install
51-
```
69+
- [Install and run directly](#install-and-run-directly) require runtime tools
70+
installed in your SO.
71+
- [Install and run with make](#install-and-run-using-make) require runtime tools
72+
and "make" installed in your SO.
73+
- [Install and in Docker](#install-and-running-with-docker-) require Docker and
74+
docker-compose installed.
75+
- (⭐️)
76+
[Install and in Docker with make](#install-and-running-with-docker--using-make)
77+
require docker-compose and make installed.
5278

53-
Or using make
79+
⭐️: Prefered way.
5480

55-
```text
56-
make dependencies
57-
```
81+
### Install and Run directly
5882

59-
### Testing silently
83+
Using a NodeJS runtime in your SO. You must install dependencies:
84+
85+
```bash
86+
npm install
87+
```
6088

6189
Every problem is a function with unit test.
90+
6291
Unit test has test cases and input data to solve the problem.
6392

6493
Run all tests:
6594

66-
```text
95+
```bash
6796
npm run test
6897
```
6998

70-
### Testing with full logs
99+
#### Test run with alternative behaviors
71100

72-
Run all tests with debug outputs:
101+
You can change test running behaviour using some environment variables as follows:
73102

74-
```text
103+
| Variable | Values | Default |
104+
| ------ | ------ | ------ |
105+
| LOG_LEVEL | `debug`, `warning`, `error`, `info` | `info` |
106+
| BRUTEFORCE | `true`, `false`| `false` |
107+
108+
- `LOG_LEVEL`: change verbosity level in outputs.
109+
- `BRUTEFORCE`: enable or disable running large tests.
110+
(long time, large amount of data, high memory consumition).
111+
112+
#### Examples running tests with alternative behaviors
113+
114+
Run tests with debug outputs:
115+
116+
```bash
75117
LOG_LEVEL=debug npm run test
76118
```
77119

78-
Use one of following values: debug, warning, error, info.
79-
80-
### Testing using make
120+
Run brute-force tests with debug outputs:
81121

82-
```text
83-
make test
122+
```bash
123+
BRUTEFORCE=true LOG_LEVEL=debug npm run test
84124
```
85125

86-
#### Enable all large BRUTEFORCE tests
126+
### Install and Run using make
87127

88-
Direct in host using a make:
128+
`make` tool is used to standardizes the commands for the same tasks
129+
across each sibling repository.
89130

90-
```text
91-
make test -e BRUTEFORCE=true
131+
Run tests (libraries are installed as dependency task in make):
132+
133+
```bash
134+
make test
92135
```
93136

94-
#### Enable all DEBUG outputs
137+
Run tests with debug outputs:
95138

96-
```text
139+
```bash
97140
make test -e LOG_LEVEL=debug
98141
```
99142

100-
#### Enable all large BRUTEFORCE tests and all DEBUG outputs
143+
Run brute-force tests with debug outputs:
101144

102-
```text
103-
make test -e LOG_LEVEL=debug -e BRUTEFORCE=true
145+
```bash
146+
make test -e BRUTEFORCE=true -e LOG_LEVEL=debug
104147
```
105148

106-
## Running with Docker 🐳
149+
Alternative way, use environment variables as prefix:
107150

108-
## Build a complete image with and run all tests
151+
```bash
152+
BRUTEFORCE=true LOG_LEVEL=debug make test
153+
```
109154

110-
Running container with testing (final) target.
155+
### Install and Running with Docker 🐳
111156

112-
Designed to store all application files and dependencies as a complete runnable image.
113-
Coverage results will be stored in host **/coverage** directory (mounted as volume).
157+
Build an image of the test stage.
158+
Then creates and ephemeral container an run tests.
114159

115-
```text
116-
# Build a complete image
117-
docker-compose build algorithm-exercises-js
118-
docker-compose run --rm algorithm-exercises-js npm run test
160+
BRUTEFORCE and LOG_LEVEL environment variables are passing from current
161+
environment using docker-compose.
162+
163+
```bash
164+
docker-compose --profile testing run --rm algorithm-exercises-js-test
119165
```
120166

121-
### Enable BRUTEFORCE tests with full DEBUG output
167+
To change behavior using environment variables, you can pass to containers
168+
in the following ways:
122169

123-
With docker-compose:
170+
From host using docker-compose (compose.yaml) mechanism:
124171

125-
```text
126-
docker-compose --profile testing run --rm algorithm-exercises-js make test -e LOG_LEVEL=DEBUG -e BRUTEFORCE=true
172+
```bash
173+
BRUTEFORCE=true LOG_LEVEL=debug docker-compose --profile testing run --rm algorithm-exercises-js-test
127174
```
128175

129-
Using make:
176+
Overriding docker CMD, as parameter of make "-e":
130177

131-
```text
132-
make docker/compose-run -e LOG_LEVEL=DEBUG -e BRUTEFORCE=true
178+
```bash
179+
docker-compose --profile testing run --rm algorithm-exercises-js-test make test -e LOG_LEVEL=DEBUG -e BRUTEFORCE=true
180+
```
181+
182+
### Install and Running with Docker 🐳 using make
183+
184+
```bash
185+
make compose/build
186+
make compose/test
187+
```
188+
189+
To pass environment variables you can use docker-compose
190+
or overriding CMD and passing to make as "-e" argument.
191+
192+
Passing environment variables using docker-compose (compose.yaml mechanism):
193+
194+
```bash
195+
BRUTEFORCE=true LOG_LEVEL=debug make compose/test
133196
```
134197

135-
### Build and run a development image
198+
## Development workflow using Docker / docker-compose
136199

137200
Running container with development target.
138-
Designed to develop on top of this image. All source application is mounted as
139-
a volume in **/app** directory.
140-
Dependencies should be installed to run (not present in this target) so, you
141-
must install dependencies before run (or after a dependency add/change).
201+
Designed for development workflow on top of this image.
202+
All source application is mounted as a volume in **/app** directory.
203+
Dependencies should be installed to run so, you must
204+
install dependencies before run (or after a dependency add/change).
142205

143-
```text
144-
# install node_modules dependencies using docker runtime and store them in host directory
206+
```bash
207+
# Build development target image
145208
docker-compose build --compress algorithm-exercises-js-dev
209+
# run ephemeral container to install dependencies using docker runtime
210+
# and store them in host directory (by bind-mount volume)
146211
docker-compose run --rm algorithm-exercises-js-dev npm install --verbose
212+
# Run ephemeral container and override command to run test
147213
docker-compose run --rm algorithm-exercises-js-dev npm run test
148214
```
149215

216+
## Run complete workflow (Docker + make)
217+
218+
Following command simulates a standarized pipeline across environments,
219+
using docker-compose and make.
220+
221+
```bash
222+
make compose/build && make compose/lint && make compose/test && make compose/run
223+
```
224+
225+
- Build all Docker stages and tag relevant images.
226+
- Run static analysis (lint) checks
227+
- Run unit tests
228+
- Run a "final" production ready image as a final container.
229+
Final "production" image just shows a minimal "production ready"
230+
build (with no tests).
231+
150232
## About development
151233

152234
Developed with runtime:
153235

154236
```text
155237
node --version
156-
v22.1.0
238+
v22.2.0
239+
```
240+
241+
## Algorithm excersices sources
242+
243+
- [Leetcode](https://leetcode.com/) online platform for
244+
coding interview preparation.
245+
- [HackerRank](https://www.hackerrank.com/) competitive programming challenges
246+
for both consumers and businesses.
247+
- [Project Euler](https://projecteuler.net/) a series of computational problems
248+
intended to be solved with computer programs.
249+
250+
Use these answers to learn some tip and tricks for algorithms tests.
251+
252+
### Disclaimer. Why I publish solutions?
253+
254+
As Project Euler says:
255+
256+
<https://projecteuler.net/about#publish>
257+
258+
```text
259+
I learned so much solving problem XXX, so is it okay to publish my solution elsewhere?
260+
It appears that you have answered your own question. There is nothing quite like that "Aha!" moment when you finally beat a problem which you have been working on for some time. It is often through the best of intentions in wishing to share our insights so that others can enjoy that moment too. Sadly, that will rarely be the case for your readers. Real learning is an active process and seeing how it is done is a long way from experiencing that epiphany of discovery. Please do not deny others what you have so richly valued yourself.
261+
262+
However, the rule about sharing solutions outside of Project Euler does not apply to the first one-hundred problems, as long as any discussion clearly aims to instruct methods, not just provide answers, and does not directly threaten to undermine the enjoyment of solving later problems. Problems 1 to 100 provide a wealth of helpful introductory teaching material and if you are able to respect our requirements, then we give permission for those problems and their solutions to be discussed elsewhere.
157263
```
158264

265+
If you have better answers or optimal solutions, fork and PR-me
266+
267+
Enjoy 😁 !
268+
269+
## Status
270+
159271
### License
160272

161273
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fsir-gon%2Fprojecteuler-js.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fsir-gon%2Fprojecteuler-js?ref=badge_large)

0 commit comments

Comments
 (0)