Skip to content

Commit

Permalink
refactor: modify condition based on es2020 (#2020)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalarangelo authored Sep 29, 2023
2 parents 10c20a3 + b4d34df commit 2db3c17
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions content/snippets/js/s/value-frequencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ language: javascript
tags: [array,object]
author: chalarangelo
cover: tropical-waterfall
dateModified: 2020-10-19
dateModified: 2023-09-27
---

Creates an object with the unique values of an array as keys and their frequencies as the values.
Expand All @@ -15,7 +15,7 @@ Creates an object with the unique values of an array as keys and their frequenci
```js
const frequencies = arr =>
arr.reduce((a, v) => {
a[v] = a[v] ? a[v] + 1 : 1;
a[v] = (a[v] ?? 0) + 1;
return a;
}, {});
```
Expand Down

0 comments on commit 2db3c17

Please sign in to comment.