We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 10c20a3 + b4d34df commit 2db3c17Copy full SHA for 2db3c17
content/snippets/js/s/value-frequencies.md
@@ -5,7 +5,7 @@ language: javascript
5
tags: [array,object]
6
author: chalarangelo
7
cover: tropical-waterfall
8
-dateModified: 2020-10-19
+dateModified: 2023-09-27
9
---
10
11
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
15
```js
16
const frequencies = arr =>
17
arr.reduce((a, v) => {
18
- a[v] = a[v] ? a[v] + 1 : 1;
+ a[v] = (a[v] ?? 0) + 1;
19
return a;
20
}, {});
21
```
0 commit comments