Skip to content

Instantly share code, notes, and snippets.

@adrifmonte
adrifmonte / shortenConstant.js
Created October 17, 2019 17:55
shorten constant to fit maximum length accepted by sentry
// shorten constant to fit maximum length accepted by sentry
const shortenConstant = (constantCaseString, maxlength = 25, separator = '_') => {
// no need to shorten
if (!constantCaseString || constantCaseString.length < maxlength) {
return constantCaseString;
}
// abbreviate each word to fit the max length
const splittedConstantCaseTokens = constantCaseString.split(separator);
if (splittedConstantCaseTokens.length > 1) {
const solve = (people, umbrellas, result = 0) => {
if (!people) return result;
const bestUmbrellaToPick = umbrellas.reduce((best, umbrella) => {
return umbrella > best && umbrella <= people ? umbrella : best
}, 0);
if (!bestUmbrellaToPick) return -1;
const quantity = parseInt(people/bestUmbrellaToPick);