I discovered that the JavaScript sets are ordered but don't offer a method to take the first element out of the set. For the arrays this operation exists and it's called shift.
A very basic implementation can be written in this way:
function shiftSet(s) {
let res;
for (let v of s) {
res= v;
break;
}
s.delete(res);
return res;
}
Do you see a better way to write it?