Skip to content

Commit 8164eee

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] ESLint manual fixes
1 parent b61db94 commit 8164eee

Some content is hidden

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

46 files changed

+256
-223
lines changed

src/hackerrank/implementation/breakingRecords.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
export function breakingRecords(scores: number[]): number[] {
6-
if (scores.length == 0) {
6+
if (scores.length === 0) {
77
throw new Error('Empty input');
88
}
99

src/hackerrank/implementation/kangaroo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export function kangaroo(
88
x2: number,
99
v2: number
1010
): string {
11-
if (v1 == v2) {
12-
if (x1 != x2) return 'NO';
11+
if (v1 === v2) {
12+
if (x1 !== x2) return 'NO';
1313
return 'YES';
1414
}
1515

src/hackerrank/implementation/migratoryBirds.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface Birds {
99
}
1010

1111
export function migratoryBirds(arr: number[]): number {
12-
if (arr.length == 0) {
12+
if (arr.length === 0) {
1313
throw new Error('Empty input');
1414
}
1515

@@ -28,7 +28,7 @@ export function migratoryBirds(arr: number[]): number {
2828
console.debug(`bird = ${bird} ~> map[bird] = ${map[bird]}`);
2929
console.debug(`max = ${max} ~> map[max] = ${map[max]}`);
3030

31-
if (map[bird] > map[max] || (map[bird] == map[max] && bird < max))
31+
if (map[bird] > map[max] || (map[bird] === map[max] && bird < max))
3232
max = bird;
3333
}
3434

src/hackerrank/implementation/minimumAbsoluteDifference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { logger as console } from '../../logger';
66

77
export function minimumAbsoluteDifference(arr: number[]): number {
8-
if (arr.length == 0) {
8+
if (arr.length === 0) {
99
throw new Error('Empty input');
1010
}
1111

src/hackerrank/implementation/sockMerchant.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ export function sockMerchant(n: number, ar: number[]): number {
1919

2020
console.debug(matches);
2121

22-
for (const k in matches) {
23-
console.debug(matches[k]);
22+
for (const match of Object.values(matches)) {
23+
console.debug(match);
2424

25-
result += Math.floor(matches[k] / 2);
25+
result += Math.floor(match / 2);
2626
}
2727

2828
return result;

src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from '@jest/globals';
22
import { logger as console } from '../../../logger';
33

4-
import { default as TEST_CASES } from './cruch_testcases_test.json';
4+
import TEST_CASES from './cruch_testcases_test.json';
55

66
import { arrayManipulation } from './cruch_bruteforce';
77

src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export function arrayManipulation(n: number, queries: number[][]): number {
1212
let maximum = 0;
1313

1414
queries.forEach((query) => {
15-
const [a_start, b_end, k_value] = query;
15+
const [aStart, bEnd, kValue] = query;
1616
console.debug(`start -> ${result}`);
1717

18-
for (let i = a_start; i <= b_end; i++) {
19-
result[i] += k_value;
18+
for (let i = aStart; i <= bEnd; i++) {
19+
result[i] += kValue;
2020
console.debug(`result -> ${result}`);
2121
}
2222
});
@@ -27,3 +27,5 @@ export function arrayManipulation(n: number, queries: number[][]): number {
2727

2828
return maximum;
2929
}
30+
31+
export default { arrayManipulation };

src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from '@jest/globals';
22
import { logger as console } from '../../../logger';
33

4-
import { default as TEST_CASES } from './cruch_testcases_test.json';
4+
import TEST_CASES from './cruch_testcases_test.json';
55

66
import { arrayManipulation } from './cruch_optimized';
77

src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@
55
export function arrayManipulation(n: number, queries: number[][]): number {
66
// why adding 2?
77
// first slot to adjust 1-based index and
8-
// last slot for storing accum_sum result
8+
// last slot for storing accumSum result
99
const LENGTH = n + 2;
1010
const INITIAL_VALUE = 0;
1111
const result = Array(LENGTH).fill(INITIAL_VALUE);
1212
let maximum = 0;
1313

1414
queries.forEach((query) => {
15-
const [a_start, b_end, k_value] = query;
15+
const [aStart, bEnd, kValue] = query;
1616

17-
result[a_start] += k_value;
18-
result[b_end + 1] -= k_value;
17+
result[aStart] += kValue;
18+
result[bEnd + 1] -= kValue;
1919
});
2020

21-
let accum_sum = 0;
21+
let accumSum = 0;
2222

2323
result.forEach((value) => {
24-
accum_sum += value;
25-
maximum = Math.max(maximum, accum_sum);
24+
accumSum += value;
25+
maximum = Math.max(maximum, accumSum);
2626
});
2727

2828
return maximum;
2929
}
30+
31+
export default { arrayManipulation };

src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
* @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.md]]
33
*/
44

5-
export function rotLeftOne(a_numbers: number[]): number[] {
6-
const first = a_numbers.shift();
7-
if (first != undefined) {
8-
a_numbers.push(first);
5+
export function rotLeftOne(aNumbers: number[]): number[] {
6+
const first = aNumbers.shift();
7+
if (first !== undefined) {
8+
aNumbers.push(first);
99
}
1010

11-
return a_numbers;
11+
return aNumbers;
1212
}
1313

14-
export function rotLeft(a_numbers: number[], d_rotations: number): number[] {
15-
let output = [...a_numbers];
14+
export function rotLeft(aNumbers: number[], dRotations: number): number[] {
15+
let output = [...aNumbers];
1616

17-
for (let i = 0; i < d_rotations; i++) {
17+
for (let i = 0; i < dRotations; i++) {
1818
output = rotLeftOne(output);
1919
}
2020

src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
*/
44

55
export function minimumSwaps(arr: number[]): number {
6-
const indexed_group = arr.map((x) => x - 1);
6+
const indexedGroup = arr.map((x) => x - 1);
77
let swaps = 0;
88
let index = 0;
9-
const size = indexed_group.length;
9+
const size = indexedGroup.length;
1010

1111
while (index < size) {
12-
if (indexed_group[index] == index) {
12+
if (indexedGroup[index] === index) {
1313
index += 1;
1414
} else {
15-
const temp = indexed_group[index];
16-
indexed_group[index] = indexed_group[temp];
17-
indexed_group[temp] = temp;
15+
const temp = indexedGroup[index];
16+
indexedGroup[index] = indexedGroup[temp];
17+
indexedGroup[temp] = temp;
1818
swaps += 1;
1919
}
2020
}

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function countTriplets(arr: number[], ratio: number): number {
1313
for (let k = j + 1; k < size; k++) {
1414
console.debug(`${arr[i]}, ${arr[j]}, ${arr[k]}`);
1515

16-
if (ratio * arr[i] == arr[j] && ratio * arr[j] == arr[k]) {
16+
if (ratio * arr[i] === arr[j] && ratio * arr[j] === arr[k]) {
1717
counter += 1;
1818
}
1919
}

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optmized.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
export function countTriplets(arr: number[], ratio: number): number {
77
let triplets = 0;
88

9-
const a_counter: Record<number, number> = arr.reduce(
9+
const aCounter: Record<number, number> = arr.reduce(
1010
(accumulator: Record<number, number>, entry: number) => {
1111
if (entry in accumulator) {
1212
accumulator[entry] += 1;
@@ -18,20 +18,20 @@ export function countTriplets(arr: number[], ratio: number): number {
1818
{}
1919
);
2020

21-
const b_counter: Record<number, number> = {};
21+
const bCounter: Record<number, number> = {};
2222

2323
arr.forEach((x) => {
2424
const j = Math.floor(x / ratio);
2525
const k = x * ratio;
26-
a_counter[x] -= 1;
27-
if (b_counter[j] && a_counter[k] && x % ratio == 0) {
28-
triplets += b_counter[j] * a_counter[k];
26+
aCounter[x] -= 1;
27+
if (bCounter[j] && aCounter[k] && x % ratio === 0) {
28+
triplets += bCounter[j] * aCounter[k];
2929
}
3030

31-
if (x in b_counter) {
32-
b_counter[x] += 1;
31+
if (x in bCounter) {
32+
bCounter[x] += 1;
3333
} else {
34-
b_counter[x] = 1;
34+
bCounter[x] = 1;
3535
}
3636
});
3737

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/frequency_queries_bruteforce.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Complete the freqQuery function below.
77
export function freqQuery(queries: number[][]): number[] {
88
const result: number[] = [];
9-
const data_map: Record<number, number> = {};
9+
const dataMap: Record<number, number> = {};
1010

1111
const __INITIAL__ = 0;
1212
const __INSERT__ = 1;
@@ -19,17 +19,17 @@ export function freqQuery(queries: number[][]): number[] {
1919
queries.forEach((query) => {
2020
const [operation, data] = query;
2121

22-
const current = data_map?.[data] ?? __INITIAL__;
22+
const current = dataMap?.[data] ?? __INITIAL__;
2323

2424
switch (operation) {
2525
case __INSERT__:
26-
data_map[data] = current + 1;
26+
dataMap[data] = current + 1;
2727
break;
2828
case __DELETE__:
29-
data_map[data] = Math.max(0, current - 1);
29+
dataMap[data] = Math.max(0, current - 1);
3030
break;
3131
case __SELECT__: {
32-
const uniqueDatavalues = new Set(Object.values(data_map));
32+
const uniqueDatavalues = new Set(Object.values(dataMap));
3333
if (uniqueDatavalues.has(data)) {
3434
result.push(__FOUND__);
3535
} else {

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/sherlock_and_anagrams.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,41 @@ export function sherlockAndAnagrams(s: string): number {
2424
// Add substrings to a candidate list.
2525
// two strings are anagrams if sorted strings are the same.
2626

27-
const anagram_candidate = substr
27+
const anagramCandidate = substr
2828
.split('')
2929
.sort((a: string, b: string) => a.localeCompare(b))
3030
.join('');
31-
if (anagram_candidate in candidates) {
32-
candidates[anagram_candidate].push(substr);
31+
if (anagramCandidate in candidates) {
32+
candidates[anagramCandidate].push(substr);
3333
} else {
34-
candidates[anagram_candidate] = [substr];
34+
candidates[anagramCandidate] = [substr];
3535
}
3636
}
3737
}
3838

3939
let total: bigint = BigInt(0);
40-
let q_candidates = 0;
40+
let qCandidates = 0;
4141
// Final Anagram list
4242
for (const word of Object.keys(candidates)) {
43-
const quantity_of_anagrams = candidates[word].length;
43+
const quantityOfAnagrams = candidates[word].length;
4444
const k = 2;
4545

46-
if (quantity_of_anagrams <= 1) {
46+
if (quantityOfAnagrams <= 1) {
4747
delete candidates[word];
4848
} else {
4949
// Binomial coefficient: https://en.wikipedia.org/wiki/Binomial_coefficient
50-
q_candidates += quantity_of_anagrams;
50+
qCandidates += quantityOfAnagrams;
5151

5252
const count =
53-
extraLongFactorials(quantity_of_anagrams) /
54-
(extraLongFactorials(k) *
55-
extraLongFactorials(quantity_of_anagrams - k));
53+
extraLongFactorials(quantityOfAnagrams) /
54+
(extraLongFactorials(k) * extraLongFactorials(quantityOfAnagrams - k));
5655
total += count;
5756

5857
console.debug(`'Partial anagrams of ${word}: ${count}`);
5958
}
6059
}
6160
console.debug(
62-
`'sherlockAndAnagrams(${s}) Filtered # candidates: ${q_candidates}`
61+
`'sherlockAndAnagrams(${s}) Filtered # candidates: ${qCandidates}`
6362
);
6463
console.debug(`'sherlockAndAnagrams(${s}) # anagrams: ${total}`);
6564

src/hackerrank/interview_preparation_kit/dynamic_programming/max_array_sum.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ const bigIntMax = (...args: bigint[]): bigint =>
99
export function maxSubsetSum(arr: number[]): number {
1010
const arrCopy: bigint[] = arr.map((x: number): bigint => BigInt(x));
1111

12-
if (arrCopy.length == 0) {
12+
if (arrCopy.length === 0) {
1313
return 0;
1414
}
1515

1616
const total = arrCopy.length;
1717

18-
if (total == 1) {
18+
if (total === 1) {
1919
return Number(arrCopy[0]);
2020
}
2121

22-
let t_max = bigIntMax(arrCopy[0], arrCopy[1]);
23-
arrCopy[1] = t_max;
22+
let tMax = bigIntMax(arrCopy[0], arrCopy[1]);
23+
arrCopy[1] = tMax;
2424

2525
for (let i = 2; i < total; i++) {
26-
t_max = bigIntMax(arrCopy[i - 2] + arrCopy[i], t_max);
27-
t_max = bigIntMax(arrCopy[i], t_max);
28-
arrCopy[i] = t_max;
26+
tMax = bigIntMax(arrCopy[i - 2] + arrCopy[i], tMax);
27+
tMax = bigIntMax(arrCopy[i], tMax);
28+
arrCopy[i] = tMax;
2929
}
3030

31-
return Number(t_max);
31+
return Number(tMax);
3232
}
3333

3434
export default { maxSubsetSum };

src/hackerrank/interview_preparation_kit/greedy_algorithms/angry_children.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ export function maxMin(k: number, arr: number[]): number {
1717

1818
return result;
1919
}
20+
21+
export default { maxMin };

src/hackerrank/interview_preparation_kit/greedy_algorithms/greedy_florist.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export function getMinimumCost(k: number, c: number[]): number {
1111
let total: number = 0;
1212

1313
let i: number = 0;
14-
flowers.forEach((flower_cost) => {
14+
flowers.forEach((flowerCost) => {
1515
const position = Math.floor(i / k);
1616

17-
total += (position + 1) * flower_cost;
17+
total += (position + 1) * flowerCost;
1818
i += 1;
1919
});
2020

src/hackerrank/interview_preparation_kit/greedy_algorithms/minimum_absolute_difference_in_an_array.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
*/
44

55
export function minimumAbsoluteDifference(arr: number[]): number {
6-
const sorted_nums = arr
6+
const sortedNums = arr
77
.map((x: number): number => x)
88
.sort((a: number, b: number): number => b - a);
99

10-
let result = Math.abs(sorted_nums[sorted_nums.length - 1] - sorted_nums[0]);
10+
let result = Math.abs(sortedNums[sortedNums.length - 1] - sortedNums[0]);
1111

12-
for (let i = 0; i < sorted_nums.length - 1; i++) {
13-
const a_value = sorted_nums[i];
14-
const b_value = sorted_nums[i + 1];
12+
for (let i = 0; i < sortedNums.length - 1; i++) {
13+
const aValue = sortedNums[i];
14+
const bValue = sortedNums[i + 1];
1515

16-
const diff = Math.abs(a_value - b_value);
16+
const diff = Math.abs(aValue - bValue);
1717

1818
result = Math.min(result, diff);
1919
}

0 commit comments

Comments
 (0)