Skip to content

Commit a95ed56

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 26b631b commit a95ed56

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
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
}

0 commit comments

Comments
 (0)