cartodb/lib/assets/javascripts/builder/data/layer-letters.js
2020-06-15 10:58:47 +08:00

24 lines
473 B
JavaScript
Executable File

var _ = require('underscore');
module.exports = {
/**
* Get the next available letter.
* @param {Array} letters e.g. ['a', 'b', 'd']
* @return {String} e.g. 'c'
*/
next: function (letters) {
return _.chain(letters)
.sort()
.reduce(function (memo, letter) {
if (letter === memo) {
return String.fromCharCode(letter.charCodeAt() + 1);
} else {
return memo;
}
}, 'a')
.value();
}
};