Skip to content

Commit 48c29e3

Browse files
author
Gonzalo Diaz
committed
[BUGFIX] [Hacker Rank] Interview Preparation Kit: Greedy Algorithms: Luck Balance. Sonarcloud javascript:S2094 issue fixed ✅.
Unexpected class with only a constructor.
1 parent b0bcdb1 commit 48c29e3

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,27 @@ class Contest {
2929
this.luck = luck;
3030
this.important = important;
3131
}
32+
33+
getLuck() {
34+
return this.luck;
35+
}
36+
37+
isImportant() {
38+
return this.important !== 0;
39+
}
3240
}
3341

3442
export function luckBalance(k, contests) {
35-
// Write your code here
3643
let importantContests = [];
3744
const nonimportantContests = [];
3845

39-
contests.forEach((contest) => {
40-
const [luck, important] = [...contest];
41-
if (important === 1) {
42-
importantContests.push(new Contest(luck, important));
46+
contests.forEach((contestData) => {
47+
const [luck, important] = [...contestData];
48+
const contest = new Contest(luck, important);
49+
if (contest.isImportant()) {
50+
importantContests.push(contest);
4351
} else {
44-
nonimportantContests.push(new Contest(luck, important));
52+
nonimportantContests.push(contest);
4553
}
4654
});
4755

@@ -55,11 +63,11 @@ export function luckBalance(k, contests) {
5563
const cut = Math.min(k, size);
5664

5765
for (let i = 0; i < cut; i++) {
58-
total += importantContests[i].luck;
66+
total += importantContests[i].getLuck();
5967
}
6068

6169
for (let i = cut; i < size; i++) {
62-
total -= importantContests[i].luck;
70+
total -= importantContests[i].getLuck();
6371
}
6472

6573
nonimportantContests.forEach((contest) => {

0 commit comments

Comments
 (0)