Checks if substrings are over maximum densities in a string.
https://github.com/pelevesque/are-substrings-under-minimum-density
https://github.com/pelevesque/are-substrings-over-maximum-occurrences
https://github.com/pelevesque/are-substrings-under-minimum-occurrences
https://www.npmjs.com/package/@pelevesque/are-substrings-over-maximum-density
npm install @pelevesque/are-substrings-over-maximum-density
Command | Description |
---|---|
npm test or npm run test |
All Tests Below |
npm run cover |
Standard Style |
npm run standard |
Coverage |
npm run unit |
Unit Tests |
const areSubstringsOverMaximumDensity = require('@pelevesque/are-substrings-over-maximum-density')
// over density returns true
// 'a' takes up 50% of the string, more than a 25% density
const str = 'aaaabbbb'
const checks = { a: 0.25 }
const result = areSubstringsOverMaximumDensity(str, checks)
// result === true
// equal to density returns false
const str = 'aaaabbbb'
const checks = { a: 0.5 }
const result = areSubstringsOverMaximumDensity(str, checks)
// result === false
// under density returns false
const str = 'a man, a hog, and a fly'
const checks = { hog: 0.5 }
const result = areSubstringsOverMaximumDensity(str, checks)
// result === false
// when one is over density, it returns true ('a' is over 25%)
const str = 'aaaabbbb'
const checks = { a: 0.25, b: 0.5, c: 0.3 }
const result = areSubstringsOverMaximumDensity(str, checks)
// result === true
// when all are under or equal to density, it returns false
const str = 'a man, a hog, and a fly'
const checks = { a: 0.5, hog: 0.5, c: 0.3 }
const result = areSubstringsOverMaximumDensity(str, checks)
// result === false