Here is my implementation.
Works with arbitrary sequences of characters , their order ("alphabet") set in the variable alphabet .
As a result, the code is capable of processing Russian E , Ukrainian Є and Ї , as well as other characters of national alphabets, which are located separately in the coding table and, when comparing, give an unpredictable result.
Under your task, you only need to collect the borders of the intervals from the page and send them for processing in the form [начало1,конец1, ... ,началоN,конецN] , examples will be found below in the tests.
function checkIntersect(groups){ groups=groups.map(function(e){return e.toLowerCase();}); //alphabet - порядок символов алфавита var alphabet="абвгдеёжзийклмнопрстуфхцчшщъыьэюя".toLowerCase(), correct=true; function diapazone(a,b){ //ищем граничные символы и подстроку между ними var p1=alphabet.indexOf(a), p2=alphabet.indexOf(b), min=p1<p2 ? p1 : p2, max=p1<p2 ? p2 : p1, substr=alphabet.substring(min,max+1); if(p1<0 || p2<0 || substr.indexOf('-')>=0) return false; //не найден символ или внутри уже меняли - косяк alphabet=alphabet.replace(substr,'-'); //ставим метку о замене return true; } for(var i=0; i<groups.length; i+=2)//перебираем диапазоны correct = correct && diapazone(groups[i],groups[i+1]); return correct; } /*************Тесты*************/ function test(c){ var res=checkIntersect(c); document.write(c[0]+"-"+c[1]+","+c[2]+"-"+c[3]+": "+res+"<br>"); } test(["а","а","б","я"])//однобуквенный интервал test(["а","м","н","я"])//типичные интервалы test(["н","я","а","м"])//обратный порядок последовательностей test(["я","н","м","а"])//развернутые последовательности test(["а","е","ё","я"])//хитрая буква Ё test(["а","я","м","н"])//включение одного интервала в другой test(["а","н","м","я"])//пересечение двух интервалов test(["а","м","н","z"])//не-алфавитные символы
>and<. - Alex Krass