Skip to content

Commit f7d6ba9

Browse files
committed
fixing stuff
1 parent 0ec3582 commit f7d6ba9

31 files changed

+454
-381
lines changed

.github/workflows/tests.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: tests
2+
on: [push]
3+
4+
jobs:
5+
test:
6+
name: Node.js ${{ matrix.node_version }}
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
node_version: [8, 10]
11+
12+
steps:
13+
- uses: actions/checkout@master
14+
- name: Use Node.js ${{ matrix.node_version }}
15+
uses: actions/setup-node@v1
16+
with:
17+
version: ${{ matrix.node_version }}
18+
- name: Test
19+
run: |
20+
npm install
21+
npm test

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
21
node_modules
3-
yarn.lock
2+
yarn.lock
3+
.DS_Store

.travis.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

changelog.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

index.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

package.json

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,49 @@
22
"name": "allalgorithms",
33
"version": "0.0.3",
44
"description": "A collection of All ▲lgorithms implemented in JavaScript",
5-
"main": "index.js",
5+
"repository": "abranhe/permutated",
66
"scripts": {
77
"test": "xo && ava"
88
},
9-
"repository": {
10-
"type": "git",
11-
"url": "git+https://github.com/abranhe/allalgorithms-js.git"
9+
"author": {
10+
"name": "Carlos Abraham",
11+
"web": "abranhe.com",
12+
"email": "abraham@abranhe.com"
1213
},
13-
"files": [
14-
"index.js",
15-
"src/"
16-
],
14+
"license": "MIT",
15+
"bugs": {
16+
"url": "https://github.com/abranhe/allalgorithms-js/issues"
17+
},
18+
"homepage": "https://js.allalgorithms.com",
19+
"files": [ "src/" ],
1720
"keywords": [
1821
"computer-science",
1922
"allalgorithms",
2023
"algorithms",
21-
"all-algorithms",
2224
"data-structures",
2325
"algorithm",
24-
"searching-algorithms",
25-
"sorting-algorithms",
26-
"graph-algorithms",
26+
"searching",
27+
"sorting",
28+
"graph",
2729
"tree",
2830
"math"
2931
],
30-
"author": {
31-
"name": "Carlos Abraham",
32-
"web": "abranhe.com",
33-
"email": "abraham@abranhe.com"
32+
"devDependencies": {
33+
"ava": "*",
34+
"xo": "*"
3435
},
35-
"license": "MIT",
36-
"bugs": {
37-
"url": "https://github.com/abranhe/allalgorithms-js/issues"
36+
"xo": {
37+
"prettier": true,
38+
"space": true,
39+
"rules": {
40+
"no-warning-comments": 0,
41+
"import/no-unassigned-import": 0,
42+
"camelcase": 1,
43+
"new-cap": 1
44+
}
3845
},
39-
"homepage": "https://js.allalgorithms.com",
40-
"devDependencies": {
41-
"ava": "^0.25.0",
42-
"xo": "^0.23.0"
46+
"prettier": {
47+
"trailingComma": "all",
48+
"bracketSpacing": true
4349
}
4450
}

readme.md

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
<div align="center">
2-
<a href="https://npmjs.com/allalgorithms"><img src="https://cdn.abranhe.com/projects/algorithms/logo.svg" width="30%">
3-
</a>
4-
<br>
52
<br>
63
<br>
4+
<img width="300" alt="Ink" src="https://cdn.abranhe.com/projects/algorithms/logo.svg">
75
<br>
8-
The All ▲lgorithms Javascript library
9-
<br>
6+
<a href="https://js.allalgorithms.com"><code>js.allalgorithms.com</code></a>
107
<br>
118
</div>
129

13-
<p align="center">
14-
<a href="https://travis-ci.org/abranhe/allalgorithms-js"><img src="https://img.shields.io/travis/abranhe/allalgorithms-js.svg?logo=travis" /></a>
15-
<a href="https://github.com/abranhe/allalgorithms-js/blob/master/license"><img src="https://img.shields.io/github/license/abranhe/allalgorithms-js.svg" /></a>
16-
<a href="https://github.com/allalgorithms"><img src="https://cdn.abranhe.com/projects/algorithms/badge.svg"/></a>
17-
<a href="https://github.com/abranhe/allalgorithms/allalgorithms-js"><img src="https://img.shields.io/npm/v/allalgorithms.svg"/></a>
18-
</p>
10+
> The All ▲lgorithms Javascript Library.
1911
20-
<p align="center">
21-
<br>
22-
<br>
23-
<a href="https://js.allalgorithms.com"><code>js.allalgorithms.com</code></a>
24-
</p>
12+
[![Build Status](https://github.com/abranhe/allalgorithms-js/workflows/tests/badge.svg)](https://github.com/abranhe/allalgorithms-js/actions)
13+
[![](https://img.shields.io/github/license/abranhe/allalgorithms-js.svg)](https://github.com/abranhe/allalgorithms-js/blob/master/license)
14+
[![](https://cdn.abranhe.com/projects/algorithms/badge.svg)](https://github.com/allalgorithms)
15+
[![](https://img.shields.io/npm/v/allalgorithms.svg)](https://github.com/abranhe/allalgorithms/allalgorithms-js)
2516

26-
# Why?
17+
## Why?
2718

2819
- Why not 😂
2920
- Clean and focused
@@ -51,25 +42,25 @@ console.log(allalgorithms.sorting.bubbleSort(arr));
5142
// -> [-2, 1, 2, 7, 10, 77]
5243
```
5344

54-
# Tree
45+
## Tree
5546

5647
- **Sorting**
5748
- [Bubble Sort](https://js.allalgorithms.com/sorting/bubble-sort)
5849
- [Merge Sort](https://js.allalgorithms.com/sorting/merge-sort)
5950

60-
# Related
51+
## Related
6152

6253
- [allalgorithms-python](https://github.com/abranhe/allalgorithms-python): All ▲lgorithms Python library
6354
- [allalgorithms-java](https://github.com/abranhe/allalgorithms-java): All ▲lgorithms Java library
6455

65-
# Maintainers
56+
## Maintainers
6657

6758
|[![Carlos Abraham Logo][3]][4]|
6859
| :--------------------------: |
6960
| [Carlos Abraham][4] |
7061

7162

72-
# License
63+
## License
7364

7465
[MIT][5] License © [Carlos Abraham][4]
7566

@@ -85,5 +76,4 @@ console.log(allalgorithms.sorting.bubbleSort(arr));
8576
<a href="https://github.com/abranhe/algorithms">
8677
<img src="https://cdn.abranhe.com/projects/algorithms/logo.svg" width="50px">
8778
</a>
88-
<br>
8979
</div>

src/helpers/comparator.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/**
2+
* Object comparator class, if the comparison fuction is not
3+
* passed in the contructor it will use the default compare
4+
* values.
5+
*
6+
* Equals (==)
7+
* Less than (<)
8+
* Greater than (> )
9+
*/
10+
class Comparator {
11+
constructor(compareFtn) {
12+
if (compareFtn) {
13+
this.compare = compareFtn;
14+
}
15+
}
16+
17+
/**
18+
* Compare two values. Returns 0 if the values are equal.
19+
* Returns 1 if a is greater than b and returns -1
20+
* if b is greater than a.
21+
*
22+
* @param {Object} a some value
23+
* @param {Object} b some other value
24+
*/
25+
compare(a, b) {
26+
if (a === b) {
27+
return 0;
28+
}
29+
30+
return a < b ? -1 : 1;
31+
}
32+
33+
/**
34+
* Returns true if the two values are equals.
35+
*
36+
* @example
37+
* ```
38+
* equal(3, 3);
39+
* // => true
40+
* ```
41+
*
42+
* @param {Object} a some value
43+
* @param {Object} b some other value
44+
*/
45+
equal(a, b) {
46+
return this.compare(a, b) === 0;
47+
}
48+
49+
/**
50+
* Returns true if a is greather than b.
51+
*
52+
* @example
53+
* ```
54+
* gte(7, 3);
55+
* // => true
56+
* ```
57+
*
58+
* @param {*} a some value
59+
* @param {*} b some other value
60+
*/
61+
gt(a, b) {
62+
return this.compare(a, b) > 0;
63+
}
64+
65+
/**
66+
* Returns true if a is greather than equal to b.
67+
*
68+
* @example
69+
* ```
70+
* gte(7, 3);
71+
* // => true
72+
* gte(3, 3);
73+
* // => true
74+
* ```
75+
*
76+
* @param {*} a some value
77+
* @param {*} b some other value
78+
*/
79+
gte(a, b) {
80+
return this.gt(a, b) || this.equal(a, b);
81+
}
82+
83+
/**
84+
* Returns true if a is less than b.
85+
*
86+
* @example
87+
* ```
88+
* * lt(7, 3);
89+
* // => false
90+
* ```
91+
*
92+
* @param {*} a some value
93+
* @param {*} b some other value
94+
*/
95+
lt(a, b) {
96+
return this.compare(a, b) < 0;
97+
}
98+
99+
/**
100+
* Returns true if a is less than equal to b.
101+
*
102+
* @example
103+
* ```
104+
* lte(7, 3);
105+
* // => false
106+
* lte(3, 3);
107+
* // => true
108+
* ```
109+
*
110+
* @param {*} a some value
111+
* @param {*} b some other value
112+
*/
113+
lte(a, b) {
114+
return this.lt(a, b) || this.equal(a, b);
115+
}
116+
117+
/**
118+
* Reverse compararision function.
119+
*
120+
* @example
121+
* ```
122+
* this.equal(3, 3); // => true
123+
* this.reverse();
124+
* this.equal(3, 3); // => false
125+
* ```
126+
*/
127+
reverse() {
128+
const originalCompareFn = this.compare;
129+
this.compare = (a, b) => originalCompareFn(b, a);
130+
}
131+
}
132+
133+
module.exports = Comparator;

src/helpers/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const Comparator = require('./comparator');
2+
3+
module.exports = {
4+
Comparator,
5+
};

src/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Sorting */
2+
const { bogosort, bubblesort, mergesort } = require('./sorting');
3+
/* Strings */
4+
const {
5+
anagrams,
6+
capitalize,
7+
palindrome,
8+
reverse,
9+
vowels,
10+
} = require('./strings');
11+
12+
module.exports = {
13+
/* Sorting */
14+
bogosort,
15+
bubblesort,
16+
mergesort,
17+
/* Strings */
18+
anagrams,
19+
capitalize,
20+
palindrome,
21+
reverse,
22+
vowels,
23+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy