Comparing version 0.47.0 to 0.48.0
@@ -358,2 +358,21 @@ /** | ||
/** | ||
* Frequency returns an object mapping each unique item in an array | ||
* to the number of items it occurs in the array. | ||
* | ||
* @param {Array} array input array | ||
* @returns {Object} Object of uniq values and the frequency of occurrence | ||
* | ||
* @example | ||
* const result = arrays.frequency(['a', 'b', 'a', 'c', 'a', 'c', 'b']); | ||
* console.log(result) | ||
* > { a: 3, b: 2, c: 2 } | ||
*/ | ||
function frequency (array) { | ||
return array.reduce((acc, curr) => { | ||
acc[curr] = acc[curr] ? ++acc[curr] : 1; | ||
return acc; | ||
}, {}); | ||
} | ||
/** | ||
* FromPairs takes an array of arrays with key-value pairs and returns an | ||
@@ -770,2 +789,3 @@ * object composed from key-value pairs. | ||
flatten: flatten, | ||
frequency: frequency, | ||
fromPairs: fromPairs, | ||
@@ -772,0 +792,0 @@ indexOf: indexOf, |
{ | ||
"name": "absurdum", | ||
"version": "0.47.0", | ||
"version": "0.48.0", | ||
"description": "Reductio Ad Absurdum - The Ridiculous Application of Reduce", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -63,2 +63,3 @@ [![GitHub Releases](https://img.shields.io/github/release/vanillaes/absurdum.svg)](https://github.com/vanillaes/absurdum/releases) | ||
- [flatten][arrays.flatten] | ||
- [frequency][arrays.frequency] | ||
- [fromPairs][arrays.fromPairs] | ||
@@ -96,2 +97,3 @@ - [indexOf][arrays.indexOf] | ||
[arrays.flatten]: ./docs/arrays/flatten.md | ||
[arrays.frequency]: ./docs/arrays/frequency.md | ||
[arrays.fromPairs]: ./docs/arrays/fromPairs.md | ||
@@ -98,0 +100,0 @@ [arrays.indexOf]: ./docs/arrays/indexOf.md |
@@ -15,2 +15,3 @@ export { chunk } from "./chunk.js"; | ||
export { flatten } from "./flatten.js"; | ||
export { frequency } from "./frequency.js"; | ||
export { fromPairs } from "./fromPairs.js"; | ||
@@ -17,0 +18,0 @@ export { indexOf } from "./indexOf.js"; |
@@ -15,2 +15,3 @@ export { chunk } from './chunk.js'; | ||
export { flatten } from './flatten.js'; | ||
export { frequency } from './frequency.js'; | ||
export { fromPairs } from './fromPairs.js'; | ||
@@ -17,0 +18,0 @@ export { indexOf } from './indexOf.js'; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170064
148
4297
156