Skip to content

Commit

Permalink
Merge branch 'master' into update_setup_node_to_v4
Browse files Browse the repository at this point in the history
  • Loading branch information
vil02 committed Mar 18, 2024
2 parents 7f2f11f + c2d7aa6 commit b790977
Show file tree
Hide file tree
Showing 208 changed files with 11,270 additions and 10,754 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ jobs:
node-version: "18.x"
- run: npm ci
- run: npm test
- run: npm run check-style
32 changes: 32 additions & 0 deletions .github/workflows/upload_coverage_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: upload_coverage_report

'on':
workflow_dispatch:
push:
branches:
- master
pull_request:

jobs:
upload_coverage_report:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: "18.x"

- name: Install dependencies
run: npm ci

- name: Generate coverage report
run: npm test -- --coverage

- name: Upload coverage to codecov
uses: codecov/codecov-action@v3
with:
files: "coverage/coverage-final.json"
fail_ci_if_error: true
...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ yarn-error.log*

# intelliJ workspace folder
.idea

/coverage
2 changes: 0 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
tasks:
- init: |
npm install && npm test
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.github
*.md
15 changes: 15 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"insertPragma": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
}
2 changes: 2 additions & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
* [Calculate Median](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/calculate_median.ts)
* [Degrees To Radians](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/degrees_to_radians.ts)
* [Digit Sum](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/digit_sum.ts)
* [Double Factorial Iterative](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/double_factorial_iterative.ts)
* [Euler Totient](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/euler_totient.ts)
* [Factorial](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/factorial.ts)
* [Factors](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/factors.ts)
Expand All @@ -128,6 +129,7 @@
* [Number Of Digits](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/number_of_digits.ts)
* [Pascals Triangle](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/pascals_triangle.ts)
* [Perfect Cube](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/perfect_cube.ts)
* [Perfect Number](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/perfect_number.ts)
* [Perfect Square](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/perfect_square.ts)
* [Prime Factorization](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/prime_factorization.ts)
* [Primes](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/primes.ts)
Expand Down
11 changes: 5 additions & 6 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript'
]
};

presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript'
]
}
20 changes: 10 additions & 10 deletions backtracking/all_combinations_of_size_k.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* and repeat the same process for the next number.
*/
export function generateCombinations(n: number, k: number): number[][] {
let combinationsAcc: number[][] = [];
let currentCombination: number[] = [];
const combinationsAcc: number[][] = []
const currentCombination: number[] = []

function generateAllCombos(
n: number,
Expand All @@ -20,19 +20,19 @@ export function generateCombinations(n: number, k: number): number[][] {
): number[][] {
if (k === 0) {
if (currentCombination.length > 0) {
combinationsAcc.push(currentCombination.slice());
combinationsAcc.push(currentCombination.slice())
}
return combinationsAcc;
return combinationsAcc
}

const endCursor = n - k + 2;
const endCursor = n - k + 2
for (let i = startCursor; i < endCursor; i++) {
currentCombination.push(i);
generateAllCombos(n, k - 1, i + 1);
currentCombination.pop();
currentCombination.push(i)
generateAllCombos(n, k - 1, i + 1)
currentCombination.pop()
}
return combinationsAcc;
return combinationsAcc
}

return generateAllCombos(n, k, 1);
return generateAllCombos(n, k, 1)
}
26 changes: 15 additions & 11 deletions backtracking/generateparentheses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@
*/

const generateParentheses = (n: number): string[] => {
const result: string[] = [];
const result: string[] = []

const solve = (chars: string, openParentheses: number, closedParentheses: number) => {
const solve = (
chars: string,
openParentheses: number,
closedParentheses: number
) => {
if (openParentheses === n && closedParentheses === n) {
result.push(chars);
return;
result.push(chars)
return
}

if (openParentheses <= n) {
solve(chars + "(", openParentheses + 1, closedParentheses);
solve(chars + '(', openParentheses + 1, closedParentheses)
}

if (closedParentheses < openParentheses) {
solve(chars + ")", openParentheses, closedParentheses + 1);
solve(chars + ')', openParentheses, closedParentheses + 1)
}
};
}

solve("", 0, 0);
solve('', 0, 0)

return result;
};
return result
}

export { generateParentheses };
export { generateParentheses }
33 changes: 22 additions & 11 deletions backtracking/test/all_combinations_of_size_k.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generateCombinations } from "../all_combinations_of_size_k";
import { generateCombinations } from '../all_combinations_of_size_k'

const cases = [
[
Expand All @@ -7,20 +7,31 @@ const cases = [
[
[1, 2],
[1, 3],
[2, 3]
]
],
[
4,
2,
[
[1, 2],
[1, 3],
[1, 4],
[2, 3],
],
[2, 4],
[3, 4]
]
],
[4, 2, [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]],
[0, 0, []],
[2, 3, []],
] as const;
[2, 3, []]
] as const

describe("AllCombinationsOfSizeK", () => {
describe('AllCombinationsOfSizeK', () => {
it.each(cases)(
"create all combinations given n=%p and k=%p",
'create all combinations given n=%p and k=%p',
(n, k, expectedCombos) => {
const combinations = generateCombinations(n, k);
expect(combinations).toEqual(expectedCombos);
const combinations = generateCombinations(n, k)
expect(combinations).toEqual(expectedCombos)
}
);
});
)
})
140 changes: 70 additions & 70 deletions backtracking/test/generateparentheses.test.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
import { generateParentheses } from "../generateparentheses";
import { generateParentheses } from '../generateparentheses'

const cases: [number, string[]][] = [
[0, [""]],
[1, ["()"]],
[2, ["(())", "()()"]],
[3, ["((()))", "(()())", "(())()", "()(())", "()()()"]],
[0, ['']],
[1, ['()']],
[2, ['(())', '()()']],
[3, ['((()))', '(()())', '(())()', '()(())', '()()()']],
[
4,
[
"(((())))",
"((()()))",
"((())())",
"((()))()",
"(()(()))",
"(()()())",
"(()())()",
"(())(())",
"(())()()",
"()((()))",
"()(()())",
"()(())()",
"()()(())",
"()()()()",
],
'(((())))',
'((()()))',
'((())())',
'((()))()',
'(()(()))',
'(()()())',
'(()())()',
'(())(())',
'(())()()',
'()((()))',
'()(()())',
'()(())()',
'()()(())',
'()()()()'
]
],
[
5,
[
"((((()))))",
"(((()())))",
"(((())()))",
"(((()))())",
"(((())))()",
"((()(())))",
"((()()()))",
"((()())())",
"((()()))()",
"((())(()))",
"((())()())",
"((())())()",
"((()))(())",
"((()))()()",
"(()((())))",
"(()(()()))",
"(()(())())",
"(()(()))()",
"(()()(()))",
"(()()()())",
"(()()())()",
"(()())(())",
"(()())()()",
"(())((()))",
"(())(()())",
"(())(())()",
"(())()(())",
"(())()()()",
"()(((())))",
"()((()()))",
"()((())())",
"()((()))()",
"()(()(()))",
"()(()()())",
"()(()())()",
"()(())(())",
"()(())()()",
"()()((()))",
"()()(()())",
"()()(())()",
"()()()(())",
"()()()()()",
],
],
];
'((((()))))',
'(((()())))',
'(((())()))',
'(((()))())',
'(((())))()',
'((()(())))',
'((()()()))',
'((()())())',
'((()()))()',
'((())(()))',
'((())()())',
'((())())()',
'((()))(())',
'((()))()()',
'(()((())))',
'(()(()()))',
'(()(())())',
'(()(()))()',
'(()()(()))',
'(()()()())',
'(()()())()',
'(()())(())',
'(()())()()',
'(())((()))',
'(())(()())',
'(())(())()',
'(())()(())',
'(())()()()',
'()(((())))',
'()((()()))',
'()((())())',
'()((()))()',
'()(()(()))',
'()(()()())',
'()(()())()',
'()(())(())',
'()(())()()',
'()()((()))',
'()()(()())',
'()()(())()',
'()()()(())',
'()()()()()'
]
]
]

describe("Generate Parentheses", () => {
describe('Generate Parentheses', () => {
test.each(cases)(
"generate all valid parentheses of input %n",
'generate all valid parentheses of input %n',
(n: number, expected: string[]) => {
expect(generateParentheses(n)).toStrictEqual(expected);
expect(generateParentheses(n)).toStrictEqual(expected)
}
);
});
)
})
Loading

0 comments on commit b790977

Please sign in to comment.