Skip to content

Commit 0d7aaff

Browse files
committed
chore: fix camelcasing and linting
1 parent 96e83b1 commit 0d7aaff

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

maths/test/ugly_numbers.test.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { UglyNumbers } from '../ugly_numbers';
1+
import { uglyNumbers } from "../ugly_numbers";
22

3-
test('Ugly Numbers', () => {
4-
const uglyNumbers = UglyNumbers();
5-
expect(Array(11).fill(undefined).map(() => uglyNumbers.next().value)).toEqual([1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15]);
6-
})
3+
test("Ugly Numbers", () => {
4+
const uglyNums = uglyNumbers();
5+
expect(
6+
Array(11)
7+
.fill(undefined)
8+
.map(() => uglyNums.next().value)
9+
).toEqual([1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15]);
10+
});

maths/ugly_numbers.ts

+20-18
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,34 @@
55
* They can be represented in the form 2^a * 3^b * 5*c. By convention, 1 is also considered to be
66
* an ugly number.
77
* The first few terms of the sequence are: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20...
8-
*
8+
*
99
* For the provided n, the nth ugly number shall be computed.
1010
* @see [GeeksForGeeks](https://www.geeksforgeeks.org/ugly-numbers/)
1111
*/
12-
function* UglyNumbers() {
13-
yield 1
12+
function* uglyNumbers() {
13+
yield 1;
1414

15-
let idx2 = 0, idx3 = 0, idx5 = 0
16-
const uglyNumbers = [1]
15+
let idx2 = 0,
16+
idx3 = 0,
17+
idx5 = 0;
18+
const uglyNums: number[] = [1];
1719

18-
let nextx2: number, nextx3: number, nextx5: number, nextUglyNum: number
20+
let nextx2: number, nextx3: number, nextx5: number, nextUglyNum: number;
1921

20-
while(true) {
21-
nextx2 = uglyNumbers[idx2] * 2
22-
nextx3 = uglyNumbers[idx3] * 3
23-
nextx5 = uglyNumbers[idx5] * 5
22+
while (true) {
23+
nextx2 = uglyNums[idx2] * 2;
24+
nextx3 = uglyNums[idx3] * 3;
25+
nextx5 = uglyNums[idx5] * 5;
2426

25-
nextUglyNum = Math.min(nextx2, nextx3, nextx5)
26-
yield nextUglyNum
27+
nextUglyNum = Math.min(nextx2, nextx3, nextx5);
28+
yield nextUglyNum;
2729

28-
if(nextx2 === nextUglyNum) idx2++
29-
if(nextx3 === nextUglyNum) idx3++
30-
if(nextx5 === nextUglyNum) idx5++
31-
32-
uglyNumbers.push(nextUglyNum)
30+
if (nextx2 === nextUglyNum) idx2++;
31+
if (nextx3 === nextUglyNum) idx3++;
32+
if (nextx5 === nextUglyNum) idx5++;
33+
34+
uglyNums.push(nextUglyNum);
3335
}
3436
}
3537

36-
export { UglyNumbers }
38+
export { uglyNumbers };

0 commit comments

Comments
 (0)