untitled notebook

node v6.17.1
version: 1.0.0
endpointsharetweet
function vetAppTitle(title, charLimit) { if (charLimit <= 0) { throw new Error('Character limit must be greater than zero.'); } if (title.length <= charLimit) { return title; } let space = ' '; let seperators = [',', '-', '&', ':', '(', '[', '{' , '%']; let accumulator = title; // Don't do anything if it is only one word. if (accumulator.charAt(charLimit) !== space && accumulator.trim().indexOf(space) === -1) { return title; } if (accumulator.charAt(charLimit) === space) { accumulator = accumulator.slice(0, charLimit).trim(); } else { for(let i = charLimit; i < accumulator.length ; i++) { if (accumulator.charAt(i) === space) { accumulator = accumulator.slice(0, i).trim(); break; } } } if (accumulator.lastIndexOf(space) !== -1) { accumulator = accumulator.slice(0, accumulator.lastIndexOf(space)).trim(); } for(let i = 0; i < seperators.length; i++) { accumulator = (accumulator.split(seperators[i])[0]).trim(); } return accumulator; } vetAppTitle('Famous quotes of', 3);
Loading…

no comments

    sign in to comment