Skip to content

pelevesque-node/are-substrings-over-maximum-density

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status JavaScript Style Guide

are-substrings-over-maximum-density

Checks if substrings are over maximum densities in a string.

Related Packages

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

Node Repository

https://www.npmjs.com/package/@pelevesque/are-substrings-over-maximum-density

Installation

npm install @pelevesque/are-substrings-over-maximum-density

Tests

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

Usage

Requiring

const areSubstringsOverMaximumDensity = require('@pelevesque/are-substrings-over-maximum-density')

One Check

// 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

Multiple Checks

// 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

About

Checks if substrings are over maximum densities in a string.

Resources

License

Stars

Watchers

Forks

Packages

No packages published