Skip to content

Commit 61e6036

Browse files
author
Gonzalo Diaz
committed
[BUGFIX] sonarqube: Prefer Math.max() to simplify ternary expressions.
Ternary expressions should be replaced with "Math.min()" or "Math.max()" for simple comparisons typescript:S7766
1 parent 624b029 commit 61e6036

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/hackerrank/interview_preparation_kit/dynamic_programming/max_array_sum.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
*/
55

66
const bigIntMax = (...args: bigint[]): bigint =>
7-
args.reduce((m, e) => (e > m ? e : m), BigInt(0));
7+
args.reduce((m, e) => {
8+
const _e = BigInt(e);
9+
const _m = BigInt(m);
10+
return _e > _m ? _e : _m;
11+
}, BigInt(0));
812

913
function maxSubsetSum(arr: number[]): number {
1014
const arrCopy: bigint[] = arr.map((x: number): bigint => BigInt(x));

src/projecteuler/problem0005.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function _replaceMaximum(
3333
const element = _group.get(_element);
3434

3535
if (element) {
36-
_group.set(_element, count > element ? count : element);
36+
_group.set(_element, Math.max(count, element));
3737
} else {
3838
_group.set(_element, count);
3939
}

src/projecteuler/problem0018.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function problem0018(_triangle: number[][]): number {
3232
console.debug(`leafs: ${leafs.toString()}`);
3333

3434
const __START_FROM__ = 0;
35-
const max = leafs.reduce((a, b) => (a > b ? a : b), __START_FROM__);
35+
const max = leafs.reduce((a, b) => Math.max(a, b), __START_FROM__);
3636

3737
return max;
3838
}

0 commit comments

Comments
 (0)