Skip to content

Commit 9c35031

Browse files
committed
fix: linter fixes
1 parent 2c1011a commit 9c35031

File tree

8 files changed

+203
-30
lines changed

8 files changed

+203
-30
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7+
"lint": "./node_modules/.bin/eslint ./src",
78
"coverage": "jest --coverage",
89
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
910
"test": "jest --verbose",

src/_Problems_/max-product-of-3-numbers/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function maxProductof3NumbersII(arr) {
3434
throw new Error('Invalid Argument');
3535
}
3636

37+
// eslint-disable-next-line no-multi-assign
3738
let firstMax = (secondMax = thirdMax = Number.MIN_SAFE_INTEGER);
3839
let firstMin = (secondMin = Number.MAX_SAFE_INTEGER);
3940

src/_Problems_/max-product-of-3-numbers/max-product-of-3-numbers.test.js

+174-11
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,200 @@
1-
const { maxProductof3Numbers, maxProductof3NumbersII } = require(".");
1+
const { maxProductof3Numbers, maxProductof3NumbersII } = require('.');
22

3-
describe("Maximum Product of three numbers", () => {
4-
it("throws an error with no Array is passed", () => {
3+
describe('Maximum Product of three numbers', () => {
4+
it('throws an error with no Array is passed', () => {
55
expect(() => {
6-
maxProductof3Numbers("xunda");
6+
maxProductof3Numbers('xunda');
77
}).toThrowError();
88
expect(() => {
9-
maxProductof3NumbersII("xunda");
9+
maxProductof3NumbersII('xunda');
1010
}).toThrowError();
1111
});
1212

13-
it("returns the product of an array with 3 numbers", () => {
13+
it('returns the product of an array with 3 numbers', () => {
1414
expect(maxProductof3Numbers([1, 2, 3])).toEqual(6);
1515
expect(maxProductof3NumbersII([1, 2, 3])).toEqual(6);
1616
});
1717

18-
it("returns the product of an array with positive and negative numbers", () => {
18+
it('returns the product of an array with positive and negative numbers', () => {
1919
expect(maxProductof3Numbers([-10, -10, 2, 3])).toEqual(300);
2020
expect(maxProductof3NumbersII([-10, -10, 2, 3])).toEqual(300);
2121
});
2222

23-
it("returns the product of an array with negative numbers", () => {
23+
it('returns the product of an array with negative numbers', () => {
2424
expect(maxProductof3Numbers([-10, -1, -2, -10])).toEqual(-20);
2525
expect(maxProductof3NumbersII([-10, -1, -2, -10])).toEqual(-20);
2626
});
2727

28-
it("returns the proper calculation if the array is large", () => {
29-
const largeArray = [100, 100, 100, 12, 3, 45, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 1, 12, 3, 45, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 1, 12, 3, 45, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 45, 4, 3, 7, 8, 1, 3, 7, 8, 3, 45, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 1, 12, 3, 45, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 1, 12, 3, 45, 4, 3, 7, 8, 1, 3, 7, 8, 1, 4, 3, 7, 8, 1, 3, 7, 8, 45, 4, 3, 7, 8, 1, 3, 7, 8];
28+
it('returns the proper calculation if the array is large', () => {
29+
const largeArray = [
30+
100,
31+
100,
32+
100,
33+
12,
34+
3,
35+
45,
36+
4,
37+
3,
38+
7,
39+
8,
40+
1,
41+
3,
42+
7,
43+
8,
44+
1,
45+
4,
46+
3,
47+
7,
48+
8,
49+
1,
50+
3,
51+
7,
52+
8,
53+
1,
54+
12,
55+
3,
56+
45,
57+
4,
58+
3,
59+
7,
60+
8,
61+
1,
62+
3,
63+
7,
64+
8,
65+
1,
66+
4,
67+
3,
68+
7,
69+
8,
70+
1,
71+
3,
72+
7,
73+
8,
74+
1,
75+
4,
76+
3,
77+
7,
78+
8,
79+
1,
80+
3,
81+
7,
82+
8,
83+
1,
84+
12,
85+
3,
86+
45,
87+
4,
88+
3,
89+
7,
90+
8,
91+
1,
92+
3,
93+
7,
94+
8,
95+
1,
96+
4,
97+
3,
98+
7,
99+
8,
100+
1,
101+
3,
102+
7,
103+
8,
104+
45,
105+
4,
106+
3,
107+
7,
108+
8,
109+
1,
110+
3,
111+
7,
112+
8,
113+
3,
114+
45,
115+
4,
116+
3,
117+
7,
118+
8,
119+
1,
120+
3,
121+
7,
122+
8,
123+
1,
124+
4,
125+
3,
126+
7,
127+
8,
128+
1,
129+
3,
130+
7,
131+
8,
132+
1,
133+
12,
134+
3,
135+
45,
136+
4,
137+
3,
138+
7,
139+
8,
140+
1,
141+
3,
142+
7,
143+
8,
144+
1,
145+
4,
146+
3,
147+
7,
148+
8,
149+
1,
150+
3,
151+
7,
152+
8,
153+
1,
154+
4,
155+
3,
156+
7,
157+
8,
158+
1,
159+
3,
160+
7,
161+
8,
162+
1,
163+
12,
164+
3,
165+
45,
166+
4,
167+
3,
168+
7,
169+
8,
170+
1,
171+
3,
172+
7,
173+
8,
174+
1,
175+
4,
176+
3,
177+
7,
178+
8,
179+
1,
180+
3,
181+
7,
182+
8,
183+
45,
184+
4,
185+
3,
186+
7,
187+
8,
188+
1,
189+
3,
190+
7,
191+
8,
192+
];
30193
expect(maxProductof3Numbers(largeArray)).toEqual(100 * 100 * 100);
31194
expect(maxProductof3NumbersII(largeArray)).toEqual(100 * 100 * 100);
32195
});
33196

34-
it("returns an error if there are less than 3 numbers", () => {
197+
it('returns an error if there are less than 3 numbers', () => {
35198
expect(() => {
36199
maxProductof3Numbers([-10, -1]);
37200
}).toThrowError();

src/_Problems_/next-greater-element/next-greater-element.test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const { nextGreaterElement } = require('.');
22

33
describe('Next greater element', () => {
44
it('returns next greater elements collection', () => {
5-
const input = [4, 6, 3, 2, 8, 1]
6-
const greaterElements = [6, 8, 8, 8, -1, -1]
5+
const input = [4, 6, 3, 2, 8, 1];
6+
const greaterElements = [6, 8, 8, 8, -1, -1];
77

88
expect(nextGreaterElement(input)).toEqual(greaterElements);
99
});
@@ -17,22 +17,22 @@ describe('Next greater element', () => {
1717
});
1818

1919
it('returns a collection of -1 if there is no greater element', () => {
20-
const input = [90, 40, 15, 7, -1, -10]
21-
const greaterElements = [-1, -1, -1, -1, -1, -1]
20+
const input = [90, 40, 15, 7, -1, -10];
21+
const greaterElements = [-1, -1, -1, -1, -1, -1];
2222

2323
expect(nextGreaterElement(input)).toEqual(greaterElements);
2424
});
2525

2626
it('uses -1 if the numbers are the same', () => {
27-
const input = [90, 90]
28-
const greaterElements = [-1, -1]
27+
const input = [90, 90];
28+
const greaterElements = [-1, -1];
2929

3030
expect(nextGreaterElement(input)).toEqual(greaterElements);
3131
});
3232

3333
it('throws an error if the input is not an array', () => {
3434
expect(() => {
35-
nextGreaterElement('xunda')
35+
nextGreaterElement('xunda');
3636
}).toThrowError('Invalid Argument');
3737
});
3838
});

src/_Problems_/product-of-elements/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// An array such that each index has a product of all the numbers in the array except the number stored at that index.
1+
// An array such that each index has a product of all the numbers
2+
// in the array except the number stored at that index.
23

34
/**
45
* Input - [1, 2, 3, 4]
@@ -13,7 +14,8 @@ function findProduct(arr) {
1314
const result = [];
1415

1516
// multiply all the numbers to the left side
16-
for (let el of arr) {
17+
// eslint-disable-next-line no-restricted-syntax
18+
for (const el of arr) {
1719
result.push(left);
1820
left *= el;
1921
}

src/_Problems_/reverse-number/index.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function reverseNumber(num) {
1616
}
1717

1818
/**
19-
*
19+
*
2020
* Given a 32-bit signed integer, reverse digits of an integer.
2121
2222
Example 1:
@@ -32,21 +32,24 @@ function reverseNumber(num) {
3232
Input: 1534236469
3333
Output: 0 // overflows
3434
Note:
35-
Assume we are dealing with an environment which could only
36-
store integers within the 32-bit signed integer range: [−2^31, 2^31 − 1].
37-
For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
35+
Assume we are dealing with an environment which could only
36+
store integers within the 32-bit signed integer range: [−2^31, 2^31 − 1].
37+
For the purpose of this problem, assume that your function returns 0 when
38+
the reversed integer overflows.
3839
*/
3940

4041
function reverse32BitInt(x) {
4142
let isNegetive = 0;
4243
if (x < 0) {
44+
// eslint-disable-next-line no-param-reassign
4345
x *= -1;
4446
isNegetive = 1;
4547
}
4648
let reverse = 0;
4749
while (x >= 1) {
4850
const r = Math.floor(x % 10);
4951
reverse = reverse * 10 + r;
52+
// eslint-disable-next-line no-param-reassign
5053
x = Math.floor(x / 10);
5154
}
5255
if (reverse > 0x7fffffff) {
@@ -57,5 +60,5 @@ function reverse32BitInt(x) {
5760

5861
module.exports = {
5962
reverseNumber,
60-
reverse32BitInt
63+
reverse32BitInt,
6164
};

src/_Searching_/BinarySearch/BinarySearch.test.js

-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,4 @@ describe('Binary Search', () => {
3737
expect(binarySearchRecursive(array, low, high, 10)).toEqual(null);
3838
});
3939
});
40-
4140
});

src/_Searching_/BinarySearch/index.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function binarySearch(arr, key) {
66
let high = arr.length - 1;
77

88
while (low <= high) {
9-
let mid = Math.floor((low + high) / 2);
9+
const mid = Math.floor((low + high) / 2);
1010

1111
if (key < arr[mid]) {
1212
high = mid - 1;
@@ -20,16 +20,20 @@ function binarySearch(arr, key) {
2020
return null;
2121
}
2222

23+
// eslint-disable-next-line consistent-return
2324
function binarySearchRecursive(arr, low, high, key) {
2425
const mid = Math.floor((high - low) / 2 + low);
2526

2627
if (high <= low && arr[mid] !== key) {
2728
return null;
28-
} else if (key === arr[mid]) {
29+
}
30+
if (key === arr[mid]) {
2931
return mid;
30-
} else if (key < arr[mid]) {
32+
}
33+
if (key < arr[mid]) {
3134
return binarySearchRecursive(arr, low, mid - 1, key);
32-
} else if (key > arr[mid]) {
35+
}
36+
if (key > arr[mid]) {
3337
return binarySearchRecursive(arr, mid + 1, high, key);
3438
}
3539
}

0 commit comments

Comments
 (0)