Skip to content

Commit 5f49751

Browse files
committed
ts: replace || with ?? for default value on not-found values in sets
1 parent 23a2912 commit 5f49751

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

typescript/Hash Maps and Sets/geometric_sequence_triplets.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ function geometric_sequence_triplets(nums: number[], r: number): number {
33
const right_map: { [key: number]: number } = {};
44
let count = 0;
55
// Populate 'right_map' with the frequency of each element in the array.
6-
for (const x of nums)
7-
right_map[x] = (right_map[x] || 0) + 1;
6+
for (const x of nums)
7+
right_map[x] = (right_map[x] ?? 0) + 1;
88
// Search for geometric triplets that have x as the center.
99
for (const x of nums) {
10-
// Decrement the frequency of x in right_map' since x is now being
10+
// Decrement the frequency of x in right_map since x is now being
1111
// processed and is no longer to the right.
1212
right_map[x] -= 1;
1313
if (x % r === 0) {
1414
const left_value = x / r;
1515
const right_value = x * r;
16-
count += (left_map[left_value] || 0) * (right_map[right_value] || 0);
16+
count += (left_map[left_value] ?? 0) * (right_map[right_value] ?? 0);
1717
}
18-
// Increment the frequency of x in leftMap since it'll be a part of the
18+
// Increment the frequency of x in left_map since it'll be a part of the
1919
// left side of the array once we iterate to the next value of x.
20-
left_map[x] = (left_map[x] || 0) + 1;
20+
left_map[x] = (left_map[x] ?? 0) + 1;
2121
}
2222
return count;
2323
}

0 commit comments

Comments
 (0)