const classes = [
{ maxLen: 15, name: 'length-15' },
{ maxLen: 30, name: 'length-30' },
{ maxLen: 45, name: 'length-45' },
];
document.querySelectorAll('.container').forEach(n => {
const len = n.textContent.length;
const cls = classes.find(m => m.maxLen >= len);
if (cls) {
n.classList.add(cls.name);
}
});