Created
March 22, 2014 16:46
-
-
Save joemaddalone/9710219 to your computer and use it in GitHub Desktop.
find unique abbreviations from array... did not end up needing or completing this, but might be useful later
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 abbevify(items,targetLength,pos,obj){ | |
var obj = obj || {}, | |
pos = pos || 1, | |
arr = items.slice(0), | |
t = arr[0].substring(0, pos) | |
if(!obj[t]){ | |
obj[t] = arr.shift(); | |
pos=1 | |
} | |
else { | |
pos++ | |
} | |
return (arr.length>0) ? abbevify(arr, targetLength,pos, obj) : obj | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment