Skip to content

Commit dac7b0d

Browse files
committed
style: fix Prettier formatting
1 parent 8770024 commit dac7b0d

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

Maths/MobiusFunction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ export const mobiusFunction = (number) => {
2828
return primeFactorsArray.length !== new Set(primeFactorsArray).size
2929
? 0
3030
: primeFactorsArray.length % 2 === 0
31-
? 1
32-
: -1
31+
? 1
32+
: -1
3333
}

Search/JumpSearchOptimized.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
/**
22
* This version of Jump Search works for both ascending and descending sorted arrays.
3-
*
3+
*
44
* Time Complexity: O(√n)
55
* Space Complexity: O(1)
6-
*
6+
*
77
* Example:
88
* jumpSearchOptimized([1, 3, 5, 7, 9, 11], 7) -> 3
99
* jumpSearchOptimized([20, 15, 10, 5, 0], 10) -> 2
1010
*/
1111

1212
function jumpSearchOptimized(arr, target) {
13-
if (!Array.isArray(arr) || arr.length === 0) return -1;
13+
if (!Array.isArray(arr) || arr.length === 0) return -1
1414

15-
const n = arr.length;
16-
const step = Math.floor(Math.sqrt(n));
17-
let prev = 0;
15+
const n = arr.length
16+
const step = Math.floor(Math.sqrt(n))
17+
let prev = 0
1818

1919
// Detect array order
20-
const isAscending = arr[0] < arr[n - 1];
20+
const isAscending = arr[0] < arr[n - 1]
2121

2222
// Jump in blocks based on order
2323
while (prev < n) {
24-
const next = Math.min(prev + step, n);
25-
const value = arr[next - 1];
24+
const next = Math.min(prev + step, n)
25+
const value = arr[next - 1]
2626

2727
if ((isAscending && value >= target) || (!isAscending && value <= target)) {
2828
// Linear search in the found block
2929
for (let i = prev; i < next; i++) {
30-
if (arr[i] === target) return i;
30+
if (arr[i] === target) return i
3131
}
32-
return -1;
32+
return -1
3333
}
3434

35-
prev = next;
35+
prev = next
3636
}
3737

38-
return -1;
38+
return -1
3939
}
4040

41-
module.exports = { jumpSearchOptimized };
41+
module.exports = { jumpSearchOptimized }
4242

4343
/* -----------------------------------------
4444
Quick local test: run `node Search/JumpSearchOptimized.js`
@@ -48,10 +48,12 @@ if (require.main === module) {
4848
{ arr: [1, 3, 5, 7, 9, 11], target: 7 },
4949
{ arr: [20, 15, 10, 5, 0], target: 10 },
5050
{ arr: [2, 4, 6, 8, 10, 12], target: 11 },
51-
{ arr: [], target: 3 },
52-
];
51+
{ arr: [], target: 3 }
52+
]
5353

5454
tests.forEach(({ arr, target }) => {
55-
console.log(`Array: [${arr}] | Target: ${target} | Index: ${jumpSearchOptimized(arr, target)}`);
56-
});
55+
console.log(
56+
`Array: [${arr}] | Target: ${target} | Index: ${jumpSearchOptimized(arr, target)}`
57+
)
58+
})
5759
}

0 commit comments

Comments
 (0)