export class List {
constructor(list = []) {
this.list = list;
}
compare(other) {
const list1 = this.list;
const list2 = other.list;
if (list1.length === list2.length && this.isSublist(list1, list2)) return 'EQUAL';
if (list1.length > list2.length && this.isSublist(list2, list1)) return 'SUPERLIST';
if (list1.length < list2.length && this.isSublist(list1, list2)) return 'SUBLIST';
return 'UNEQUAL';
}
isSublist(smaller, larger) {
if (smaller.length === 0) return true;
for (let i = 0; i <= larger.length - smaller.length; i++) {
let match = true;
for (let j = 0; j < smaller.length; j++) {
if (smaller[j] !== larger[i + j]) {
match = false;
break;
}
}
if (match) return true;
}
return false;
}
}