Sublist

Medium
20.0% Acceptance

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

  1. Sublist: List A assumes the role of a Sublist of list B when A can be derived by removing a certain quantity (including zero) of elements from the beginning or end of B. For instance, A = [2,3], B = [1,2,3,4]. In this scenario, A is a sublist of B.

  2. Superlist: List A turns into a Superlist of List B if A totally covers B by appending additional elements to either end. For example, A = [1,2,3,4], B = [2,3]. Here, A acts as a superlist of B.

  3. Equal: The lists are Equal if all elements in A and B are precisely identical in the same sequence. For example, A = [1,2,3] and B = [1,2,3].

  4. Unequal: If none of the above situations are true, then the lists are Unequal.

Examples

  1. When A is a sublist of B
    • Input:
      A = [1, 2, 3], B = [1, 2, 3, 4, 5]
    • Output:
      A is a sublist of B
  2. When A is a sublist of B
    • Input:
      A = [3, 4, 5], B = [1, 2, 3, 4, 5]
    • Output:
      A is a sublist of B
  3. When A is a sublist of B
    • Input:
      A = [3, 4], B = [1, 2, 3, 4, 5]
    • Output:
      A is a sublist of B
  4. When A is equal to B
    • Input:
      A = [1, 2, 3], B = [1, 2, 3]
    • Output:
      A is equal to B
  5. When A is a superlist of B
    • Input:
      A = [1, 2, 3, 4, 5], B = [2, 3, 4]
    • Output:
      A is a superlist of B
  6. When A is not a superlist of, sublist of, or equal to B
    • Input:
      A = [1, 2, 4], B = [1, 2, 3, 4, 5]
    • Output:
      A is not a superlist of, sublist of or equal to B