You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
887 B
36 lines
887 B
var toArr = require('./toArr');
|
|
|
|
exports = function() {
|
|
var args = toArr(arguments);
|
|
var names = args.sort(nameSort);
|
|
var ret = {};
|
|
var idleMap = {};
|
|
|
|
for (var i = 0, len = names.length; i < len; i++) {
|
|
var str = names[i];
|
|
var nextStr = names[i + 1] || '';
|
|
if (str === nextStr) continue;
|
|
var start = false,
|
|
abbrev = '';
|
|
|
|
for (var j = 0, strLen = str.length; j < strLen; j++) {
|
|
abbrev += str[j];
|
|
if (!start && (str[j] !== nextStr[j] || j === strLen - 1))
|
|
start = true;
|
|
|
|
if (!start) {
|
|
idleMap[abbrev] = str;
|
|
} else if (!ret[abbrev] && !idleMap[abbrev]) {
|
|
ret[abbrev] = str;
|
|
}
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
};
|
|
|
|
function nameSort(a, b) {
|
|
return a === b ? 0 : a > b ? 1 : -1;
|
|
}
|
|
|
|
module.exports = exports;
|
|
|