Skip to content
This repository was archived by the owner on Nov 9, 2021. It is now read-only.

Commit 282ee8e

Browse files
committed
Improve documentation
1 parent 08fe033 commit 282ee8e

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
indent_style = tab
7+
indent_size = 2

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,37 @@
11
# selection-sort-js
22
A "Selection Sort" algorithm implementation in JavaScript
3+
4+
## Installation
5+
```bash
6+
npm install @estebanborai/selection-sort
7+
```
8+
9+
## Usage
10+
11+
### `selectionSort(arr: Array<number>): Array<number>`
12+
Sorts an array of numbers
13+
14+
```javascript
15+
import selectionSort from '@estebanborai/selection-sort';
16+
17+
const items = [-1, 10, 2, 0, 6, 8];
18+
const sorted = selectionSort(items);
19+
20+
console.log(sorted); // [-1, 0, 2, 6, 8, 10]
21+
```
22+
23+
### `findSmallest(arr: Array<number>): number
24+
Returns the index of the smallest number in the array.
25+
_This function is used internally by `selectionSort` and exported._
26+
27+
```javascript
28+
import { findSmallest } from '@estebanborai/selection-sort';
29+
30+
const items = [1, 25, 88, -10, 11];
31+
const smallestItemIndex = findSamallest(items);
32+
33+
console.log(smallestItemIndex); // 3
34+
```
35+
36+
## License
37+
Licensed under the MIT License

src/find-smallest.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/**
2-
* findSmallest finds the smallest element in an array
2+
*
3+
* @param {array} arr - Array of numbers
4+
*
5+
* Finds the smallest element in an array
36
* and returns the index.
47
*
58
*/

src/selection-sort.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import findSmallestIndex from './find-smallest';
22

3+
/**
4+
*
5+
* @param {array} arr - Array of numbers
6+
*
7+
* Sorts an array of numbers
8+
*
9+
*/
310
function selectionSort(arr) {
411
const totalItems = Number(arr.length);
512

0 commit comments

Comments
 (0)