0.0.5 • Published 4 years ago

@pelevesque/are-substrings-under-minimum-density v0.0.5

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

Build Status Coverage Status JavaScript Style Guide

are-substrings-under-minimum-density

Checks if substrings are under minimum densities in a string.

Related Packages

https://github.com/pelevesque/are-substrings-over-maximum-density
https://github.com/pelevesque/are-substrings-under-minimum-occurrences
https://github.com/pelevesque/are-substrings-over-maximum-occurrences

Node Repository

https://www.npmjs.com/package/@pelevesque/are-substrings-under-minimum-density

Installation

npm install @pelevesque/are-substrings-under-minimum-density

Tests

CommandDescription
npm test or npm run testAll Tests Below
npm run coverStandard Style
npm run standardCoverage
npm run unitUnit Tests

Usage

Requiring

const areSubstringsUnderMinimumDensity = require('@pelevesque/are-substrings-under-minimum-density')

One Check

// under density returns true
// 'a' takes up 50% of the string, less than a 75% density
const str = 'aaaabbbb'
const checks = { a: 0.75 }
const result = areSubstringsUnderMinimumDensity(str, checks)
// result === true
// equal to density returns false
const str = 'aaaabbbb'
const checks = { a: 0.5 }
const result = areSubstringsUnderMinimumDensity(str, checks)
// result === false
// over density returns false
const str = 'a man, a hog, and a fly'
const checks = { hog: 0.01 }
const result = areSubstringsUnderMinimumDensity(str, checks)
// result === false

Multiple Checks

// when one is under density, it returns true ('a' is under 75%)
const str = 'aaaabbbb'
const checks = { a: 0.75, b: 0.5 }
const result = areSubstringsUnderMinimumDensity(str, checks)
// result === true
// when all are over or equal to density, it returns false
const str = 'aaaabbbb'
const checks = { a: 0.25, bbbb: 0.5 }
const result = areSubstringsUnderMinimumDensity(str, checks)
// result === false