Skip to content
Snippets Groups Projects
Commit 1973b74e authored by xamgore's avatar xamgore
Browse files

Parser of teachers list at js

parent 88f302c6
Branches
Tags
No related merge requests found
function parseTeachers(list) {
var state = 'inb4dep',
department = { name: '', people: [] },
data = [];
list.forEach(function (line) {
var token = line.trim();
switch (state) {
case 'inb4dep':
if (!token.length)
break;
state = 'dep';
case 'dep':
token.length
? department = { name: token, people: [] }
: state = 'inb4names';
break;
case 'inb4names':
if (!token.length)
break;
state = 'names';
case 'names':
token.length
? department.people.push(token)
: (data.push(department), state = 'inb4dep');
break;
}
});
if (state === 'names') {
data.push(department);
}
return data;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment