Skip to content

Sums the digits in a string with a powerful substrings->digits feature.

License

Notifications You must be signed in to change notification settings

pelevesque-node/sum-digits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status JavaScript Style Guide

sum-digits

Sums the digits in a string with a powerful substrings->digits feature.

Node Repository

https://www.npmjs.com/package/@pelevesque/sum-digits

Installation

npm install @pelevesque/sum-digits

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

Parameters

str     (required)
options (optional) default = { substringsToDigits = null, sumPlainDigits = true }

Examples

const sumDigits = require('@pelevesque/sum-digits')
// normal summing
sumDigits('1234') // 10
// ignores non numeric characters
sumDigits('1a2!3_4.') // 10
// you can provide a hash table of substrings to digits
const substringsToDigits = { a: 1, b: 2, c: 3 }
sumDigits('1a2b3ca', { substringsToDigits: substringsToDigits }) // 13
// substrings can be of any length
const substringsToDigits = { '1p': 1000, panama: 100, nam: 10, 2: 1 }
sumDigits('1panama2', { substringsToDigits: substringsToDigits }) // 1114
// you can bypass plain digit summing and only use substringsToDigits summing
const substringsToDigits = { '1p': 1000, panama: 100, nam: 10, 2: 1 }
sumDigits('1panama2', { substringsToDigits: substringsToDigits, sumPlainDigits: false}) // 1111

About

Sums the digits in a string with a powerful substrings->digits feature.

Resources

License

Stars

Watchers

Forks

Packages

No packages published