mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-07 02:05:08 +08:00
merge: consistent list syntax in CONTRIBUTING.md
(#921)
* feat: add style and run scripts on pre-commit hooks * Update package-lock.json * Update CONTRIBUTING.md * Add period at the end of lines
This commit is contained in:
@ -13,10 +13,10 @@ make sure that you **read the whole guidelines**. If you have any doubt on the c
|
|||||||
We are very happy that you consider implementing algorithms and data structures for others! This repository is
|
We are very happy that you consider implementing algorithms and data structures for others! This repository is
|
||||||
referenced and used by learners from around the globe. Being one of our contributors, you agree and confirm that:
|
referenced and used by learners from around the globe. Being one of our contributors, you agree and confirm that:
|
||||||
|
|
||||||
* You did your work - plagiarism is not allowed.
|
- You did your work - plagiarism is not allowed.
|
||||||
* Any plagiarized work will not be merged.
|
- Any plagiarized work will not be merged.
|
||||||
* Your work will be distributed under [GNU License](LICENSE) once your pull request is merged.
|
- Your work will be distributed under [GNU License](LICENSE) once your pull request is merged.
|
||||||
* Your submitted work must fulfill our styles and standards.
|
- Your submitted work must fulfill our styles and standards.
|
||||||
|
|
||||||
**New implementation** is welcome! For example, new solutions to a problem, different representations of a graph data
|
**New implementation** is welcome! For example, new solutions to a problem, different representations of a graph data
|
||||||
structure or algorithm designs with different complexity.
|
structure or algorithm designs with different complexity.
|
||||||
@ -35,19 +35,19 @@ If you submit a pull request that resolves an open issue, please help us to keep
|
|||||||
|
|
||||||
An Algorithm is one or more functions (or classes) that:
|
An Algorithm is one or more functions (or classes) that:
|
||||||
|
|
||||||
* take one or more inputs,
|
- take one or more inputs.
|
||||||
* perform some internal calculations or data manipulations,
|
- perform some internal calculations or data manipulations.
|
||||||
* return one or more outputs,
|
- return one or more outputs.
|
||||||
* have minimal side effects.
|
- have minimal side effects.
|
||||||
|
|
||||||
Algorithms should be packaged in a way that would make it easy for readers to put them into larger programs.
|
Algorithms should be packaged in a way that would make it easy for readers to put them into larger programs.
|
||||||
|
|
||||||
Algorithms should:
|
Algorithms should:
|
||||||
|
|
||||||
* have intuitive class and function names that make their purpose clear to readers
|
- have intuitive class and function names that make their purpose clear to readers.
|
||||||
* use JavaScript naming conventions and intuitive variable names to ease comprehension
|
- use JavaScript naming conventions and intuitive variable names to ease comprehension.
|
||||||
* be flexible to take different input values
|
- be flexible to take different input values.
|
||||||
* raise JavaScript exceptions (RangeError, etc.) on erroneous input values
|
- raise JavaScript exceptions (RangeError, etc.) on erroneous input values.
|
||||||
|
|
||||||
Algorithms in this repo should not be how-to examples for existing JavaScript packages. Instead, they should perform
|
Algorithms in this repo should not be how-to examples for existing JavaScript packages. Instead, they should perform
|
||||||
internal calculations or manipulations to convert input values into different output values. Those calculations or
|
internal calculations or manipulations to convert input values into different output values. Those calculations or
|
||||||
@ -56,9 +56,9 @@ should add unique value.
|
|||||||
|
|
||||||
#### File Naming Convention
|
#### File Naming Convention
|
||||||
|
|
||||||
* filenames should use the UpperCamelCase (PascalCase) style.
|
- filenames should use the UpperCamelCase (PascalCase) style.
|
||||||
* There should be no spaces in filenames.
|
- There should be no spaces in filenames.
|
||||||
* **Example:**`UserProfile.js` is allowed but `userprofile.js`,`Userprofile.js`,`user-Profile.js`,`userProfile.js` are
|
- **Example:** `UserProfile.js` is allowed but `userprofile.js`,`Userprofile.js`,`user-Profile.js`,`userProfile.js` are
|
||||||
not.
|
not.
|
||||||
|
|
||||||
#### Module System
|
#### Module System
|
||||||
@ -114,32 +114,35 @@ Before committing, please run
|
|||||||
npm run style
|
npm run style
|
||||||
```
|
```
|
||||||
|
|
||||||
in order to apply the coding style (where it can be done automatically). If an error is shown, please figure out what's
|
In order to apply the coding style (where it can be done automatically). If an error is shown, please figure out what's
|
||||||
wrong, fix it and run standard again.
|
wrong, fix it and run standard again.
|
||||||
|
|
||||||
A few (but not all) of the things to keep in mind:
|
A few (but not all) of the things to keep in mind:
|
||||||
|
|
||||||
* Use camelCase with the leading character as lowercase for identifier names (variables and functions)
|
- Use camelCase with the leading character as lowercase for identifier names (variables and functions).
|
||||||
* Names start with a letter
|
- Names start with a letter.
|
||||||
* Follow code indentation: Always use 2 spaces for indentation of code blocks
|
- Follow code indentation: Always use 2 spaces for indentation of code blocks.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function sumOfArray (arrayOfNumbers) {
|
function sumOfArray(arrayOfNumbers) {
|
||||||
let sum = 0
|
let sum = 0
|
||||||
|
|
||||||
for (let i = 0; i < arrayOfNumbers.length; i++) {
|
for (let i = 0; i < arrayOfNumbers.length; i++) {
|
||||||
sum += arrayOfNumbers[i]
|
sum += arrayOfNumbers[i]
|
||||||
}
|
}
|
||||||
return (sum)
|
|
||||||
|
return sum
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
*
|
|
||||||
* Avoid using global variables and avoid `==`
|
- Avoid using global variables and avoid `==`.
|
||||||
* Please use `let` over `var`
|
- Please use `let` over `var`.
|
||||||
* Please refrain from using `console.log` or any other console methods
|
- Please refrain from using `console.log` or any other console methods.
|
||||||
* **Absolutely** don't use `alert`
|
- **Absolutely** don't use `alert`.
|
||||||
* We strongly recommend the use of ECMAScript 6
|
- We strongly recommend the use of ECMAScript 6.
|
||||||
* Avoid importing external libraries for basic algorithms. Only use those libraries for complicated algorithms
|
- Avoid importing external libraries for basic algorithms. Only use those libraries for complicated algorithms.
|
||||||
* Most importantly:
|
- Most importantly:
|
||||||
* **Be consistent in the use of these guidelines when submitting**
|
- **Be consistent in the use of these guidelines when submitting.**
|
||||||
* Happy coding!
|
- Happy coding!
|
||||||
|
|
||||||
Writer [@itsvinayak](https://github.com/itsvinayak), May 2020.
|
Writer [@itsvinayak](https://github.com/itsvinayak), May 2020.
|
||||||
|
Reference in New Issue
Block a user