Skip to content

Commit a6a3a62

Browse files
authored
Merge pull request #11 from aliaks-ei/migrate_to_typescript
Migrate repo to Typescript
2 parents 053ba32 + c9f5a31 commit a6a3a62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3721
-3795
lines changed

.github/workflows/editorconfig-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
- uses: actions/checkout@v2
1010
- uses: actions/setup-node@v2
1111
with:
12-
node-version: '14'
12+
node-version: '16'
1313
- run: npm ci
1414
- run: npm run editorconfig:check

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
- uses: actions/checkout@v2
1010
- uses: actions/setup-node@v2
1111
with:
12-
node-version: '14'
12+
node-version: '16'
1313
- run: npm ci
1414
- run: npm run test:unit

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
transform: {
5+
'^.+\\.ts?$': 'ts-jest',
6+
},
7+
transformIgnorePatterns: ['<rootDir>/node_modules/'],
8+
};

package-lock.json

Lines changed: 2991 additions & 3025 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"name": "js-algorithms",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "A collection of the most famous algorithms implemented in Javascript",
5-
"author": "Alexey Mozheyko",
5+
"author": "Aliaksei Mazheika",
66
"scripts": {
7-
"test:unit": "jest --silent",
7+
"test:unit": "jest",
88
"editorconfig:check": "editorconfig-checker --exclude '.git|node_modules|.DS_store'"
99
},
1010
"devDependencies": {
11+
"@types/jest": "^29.5.3",
1112
"editorconfig-checker": "^4.0.2",
12-
"jest": "^27.0.6"
13+
"ts-jest": "^29.1.1",
14+
"typescript": "^5.1.6"
1315
}
1416
}

src/binary-search/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Binary search compares the target value to the middle element of the array. If t
88

99
## Implementation
1010

11-
**_binarySearch(numArray, key)_** should return **true** if ```key``` is present in ```numArray``` and **false** otherwise.
11+
`binarySearch(numArray, key)` should return `true` if `key` is present in `numArray` and `false` otherwise.
1212

13-
For example:
13+
Example:
1414

1515
```
1616
binarySearch([5, 7, 12, 16, 36, 56, 71], 56) // true

src/binary-search/binary-search.spec.js

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

src/binary-search/index.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import binarySearch from ".";
2+
3+
describe("Binary search: ", () => {
4+
test("should return true (array contains key)", () => {
5+
const numArray = [5, 7, 12, 16, 36, 56, 71];
6+
const key = 56;
7+
8+
expect(binarySearch(numArray, key)).toBeTruthy();
9+
});
10+
11+
test("should return false (array does not contains key)", () => {
12+
const numArray = [5, 7, 12, 16, 36, 56, 71];
13+
const key = 99;
14+
15+
expect(binarySearch(numArray, key)).toBeFalsy();
16+
});
17+
18+
test("should return false (empty array passed)", () => {
19+
const key = -33;
20+
21+
expect(binarySearch([], key)).toBeFalsy();
22+
});
23+
});
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
function binarySearch(numArray = [], key) {
2-
let numArrLength = numArray.length;
1+
function binarySearch(numArray: number[] = [], key: number): boolean {
2+
const numArrLength = numArray.length;
33

44
if (!numArrLength) {
55
return false;
66
}
77

8-
let middleIndex = Math.floor(numArrLength / 2);
9-
let middleElem = numArray[middleIndex];
8+
const middleIndex = Math.floor(numArrLength / 2);
9+
const middleElem = numArray[middleIndex];
1010

1111
if (key < middleElem && numArrLength > 1) {
1212
let leftHalf = numArray.slice(0, middleIndex);
1313

1414
return binarySearch(leftHalf, key);
15-
}
16-
else if (key > middleElem && numArrLength > 1) {
15+
} else if (key > middleElem && numArrLength > 1) {
1716
let rightHalf = numArray.slice(middleIndex);
1817

1918
return binarySearch(rightHalf, key);
20-
}
21-
else {
19+
} else {
2220
return key === middleElem;
2321
}
2422
}
2523

26-
module.exports = binarySearch;
24+
export default binarySearch;

src/bubble-sort/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ The pass through the list is repeated until the list is sorted. The algorithm, w
88

99
## Implementation
1010

11-
**_bubbleSort(array)_** should return the origin ```array```, sorted with _bubble sort_.
11+
`bubbleSort(array)` should return the origin `array`, sorted with _bubble sort_.
1212

13-
For example:
13+
Example:
1414

1515
```
1616
bubbleSort([5, 3, 8, 2, 1, 4]) // [1, 2, 3, 4, 5, 8]

0 commit comments

Comments
 (0)