Skip to content

Commit 2db3c17

Browse files
authored
refactor: modify condition based on es2020 (#2020)
2 parents 10c20a3 + b4d34df commit 2db3c17

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: content/snippets/js/s/value-frequencies.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ language: javascript
55
tags: [array,object]
66
author: chalarangelo
77
cover: tropical-waterfall
8-
dateModified: 2020-10-19
8+
dateModified: 2023-09-27
99
---
1010

1111
Creates an object with the unique values of an array as keys and their frequencies as the values.
@@ -15,7 +15,7 @@ Creates an object with the unique values of an array as keys and their frequenci
1515
```js
1616
const frequencies = arr =>
1717
arr.reduce((a, v) => {
18-
a[v] = a[v] ? a[v] + 1 : 1;
18+
a[v] = (a[v] ?? 0) + 1;
1919
return a;
2020
}, {});
2121
```

0 commit comments

Comments
 (0)