Created
June 21, 2019 04:19
-
-
Save asmattic/322755fddf1a5ef2ca3b95333c91903f to your computer and use it in GitHub Desktop.
Set company abbreviation filtering out non-important words like in, and, or, etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function diff(a, b) { | |
var result = []; | |
for (var i = 0; i < a.length; i++) { | |
if (b.indexOf(a[i]) === -1) { | |
result.push(a[i]); | |
} | |
} | |
return result; | |
} | |
var ignoredWords = ['', 'in', 'and', 'the', 'to', 'of', 'for', 'is', 'inc', 'corp', 'ltd', 'co']; | |
// Create abbreviation that has the correct characters and filtered words | |
function setAbbrev(companyVar){ | |
var companyName = execution.getVariable(companyVar); | |
var companyAbbr = ''; | |
companyName = diff(companyName.trim().toLowerCase().replace(/[^a-z0-9 ]/g, ' ').split(' '), ignoredWords); | |
if (companyName.length > 1) { | |
for (var i = 0; i < companyName.length; i += 1) { | |
companyAbbr += companyName[i].charAt(0).toUpperCase(); | |
companyAbbr = companyAbbr.substring(0, 4); | |
} | |
} else { | |
companyAbbr = companyName[0].substring(0, 4).toUpperCase(); | |
} | |
return companyAbbr; | |
} | |
// Make sure to pass the OnTask variable name as a string | |
// because the setAbbv function gets the variable from execution | |
var companyAbbreviation = setAbbrev('Company_Name'); | |
execution.setVariable('Company_Abbreviation', companyAbbreviation); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment