Skip to content

Commit

Permalink
lint and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iamwill123 committed Jul 18, 2023
1 parent 14f86d6 commit 54ae477
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/lib/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ const generateRandomNumbers = ({
max = 0,
}: GenerateRandomNumbers = {}): number[] =>
Array.from({ length: n }, () =>
Math.floor(Math.random() * (max - min + 1) + min)
Math.floor(Math.random() * (max - min + 1) + min),
);

const generateRandomLetters = ({
n = 0,
letters = 'abcdefghijklmnopqrstuvwxyz',
}: GenerateRandomLetters = {}): string[] => {
return Array.from({ length: n }, () =>
letters.charAt(Math.floor(Math.random() * letters.length))
letters.charAt(Math.floor(Math.random() * letters.length)),
);
};

Expand Down Expand Up @@ -71,7 +71,7 @@ const compare = (
a: NumberOrObject,
b: NumberOrObject,
key: string = '',
order: string = 'asc'
order: string = 'asc',
): number => {
if (key) {
a = a[key];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//


type CombinationsResult = string[];

type HelperProps = {
Expand All @@ -10,7 +9,7 @@ type HelperProps = {
};

const generate_all_binary_strings_of_len_n = (
n: number
n: number,
): CombinationsResult => {
let results: CombinationsResult = [];
let startString = '';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/recursion/fibonacci/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TypeCache } from 'src/types/recursion';
// Memoization is a technique for improving the performance of recursive functions.
let cache: TypeCache = {
0: 1,
1: 1
1: 1,
};

// Fibonacci is a sequence of numbers in which each number is the sum of the two preceding numbers.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/sorts/heap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function heapify(
length: number,
i: number,
key: string,
order: string
order: string,
): Promise<void> {
return new Promise((resolve) => {
let largest = i;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/sorts/merge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function merge(
left: ArrayInput,
right: ArrayInput,
order: string,
key: string
key: string,
) {
const merged: ArrayInput[] = [];
let indexLeft: number = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/sorts/quick/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type HelperInput = {

async function quick_sort(
input: SortInput,
partitionType: string = 'lomuto'
partitionType: string = 'lomuto',
): Promise<SortOutput> {
const _s = startTime();
const {
Expand Down
4 changes: 1 addition & 3 deletions src/types/recursion/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
type TypeCache = { [key: number]: number };

export {
TypeCache
}
export { TypeCache };
2 changes: 1 addition & 1 deletion src/types/sorts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type SortInput = {
key?: SortByKey;
callback?: (
a: NumberOrObject,
b: NumberOrObject
b: NumberOrObject,
) => Promise<void> | Promise<any>;
isSorting?: () => boolean;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,65 @@ import generateAllBinaryStringsOfLenN from '../../../../src/lib/recursion/combin
const testCases = [
{
n: 3,
expected: ["000", "001", "010", "011", "100", "101", "110", "111"]
expected: ['000', '001', '010', '011', '100', '101', '110', '111'],
},
{
n: 4,
expected: ["0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"]
expected: [
'0000',
'0001',
'0010',
'0011',
'0100',
'0101',
'0110',
'0111',
'1000',
'1001',
'1010',
'1011',
'1100',
'1101',
'1110',
'1111',
],
},
{
n: 5,
expected: ["00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"]
expected: [
'00000',
'00001',
'00010',
'00011',
'00100',
'00101',
'00110',
'00111',
'01000',
'01001',
'01010',
'01011',
'01100',
'01101',
'01110',
'01111',
'10000',
'10001',
'10010',
'10011',
'10100',
'10101',
'10110',
'10111',
'11000',
'11001',
'11010',
'11011',
'11100',
'11101',
'11110',
'11111',
],
},
];

Expand All @@ -21,6 +71,6 @@ describe('generateAllBinaryStringsOfLenN', () => {
({ n, expected }) => {
const actual = generateAllBinaryStringsOfLenN(n);
expect(actual).toEqual(expected);
}
},
);
});
2 changes: 1 addition & 1 deletion test/recursion/combinations/nCk/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ describe('find_all_combinations', () => {
({ n, k, expected }) => {
const actual = find_all_combinations(n, k);
expect(actual).toEqual(expected);
}
},
);
});
2 changes: 1 addition & 1 deletion test/sorts/native/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('Native JS sort', () => {
};
const { arr: arrOfObjs } = await nativeSort(obj);
expect(arrOfObjs).toEqual(
sorted({ key, order }).arr.alphaNumericWithFloatsObjects
sorted({ key, order }).arr.alphaNumericWithFloatsObjects,
);
});
});

0 comments on commit 54ae477

Please sign in to comment.