Sublist
Objectives
Your task is to construct a JavaScript class that assists in identifying the relationship among two list/arrays. The code should examine whether one list is enclosed within the other, both lists are identical, or they are entirely different.
Different Possible Cases
-
Sublist: List
A
assumes the role of aSublist
of listB
whenA
can be derived by removing a certain quantity (including zero) of elements from the beginning or end ofB
. For instance,A = [2,3]
,B = [1,2,3,4]
. In this scenario,A
is a sublist ofB
. -
Superlist: List
A
turns into aSuperlist
of ListB
ifA
totally coversB
by appending additional elements to either end. For example,A = [1,2,3,4]
,B = [2,3]
. Here,A
acts as a superlist ofB
. -
Equal: The lists are
Equal
if all elements inA
andB
are precisely identical in the same sequence. For example,A = [1,2,3]
andB = [1,2,3]
. -
Unequal: If none of the above situations are true, then the lists are
Unequal
.
Examples
- When
A
is a sublist ofB
- Input:
A = [1, 2, 3]
,B = [1, 2, 3, 4, 5]
- Output:
A
is a sublist ofB
- Input:
- When
A
is a sublist ofB
- Input:
A = [3, 4, 5]
,B = [1, 2, 3, 4, 5]
- Output:
A
is a sublist ofB
- Input:
- When
A
is a sublist ofB
- Input:
A = [3, 4]
,B = [1, 2, 3, 4, 5]
- Output:
A
is a sublist ofB
- Input:
- When
A
is equal toB
- Input:
A = [1, 2, 3]
,B = [1, 2, 3]
- Output:
A
is equal toB
- Input:
- When
A
is a superlist ofB
- Input:
A = [1, 2, 3, 4, 5]
,B = [2, 3, 4]
- Output:
A
is a superlist ofB
- Input:
- When
A
is not a superlist of, sublist of, or equal toB
- Input:
A = [1, 2, 4]
,B = [1, 2, 3, 4, 5]
- Output:
A
is not a superlist of, sublist of or equal toB
- Input: