cartodb-4.42/lib/assets/javascripts/builder/data/layer-letters.js
2024-04-06 05:25:13 +00: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();
}
};