numListEquals function

bool numListEquals(
  1. List<num> list1,
  2. List<num> list2
)

Checks if two lists of num are equal.

This function compares each corresponding pair of numbers from the two input lists. The input lists are considered equal if they have the same length and each pair of corresponding elements are equal.

list1 and list2 are the two lists to be compared.

Returns true if the two input lists are equal, false otherwise.

Example usage:

var list1 = [1, 2, 3.5];
var list2 = [1, 2, 3.5];
var list3 = [1, 2, 3.6];
print(numListEquals(list1, list2));  // prints: true
print(numListEquals(list1, list3));  // prints: false

Implementation

bool numListEquals(List<num> list1, List<num> list2) {
  if (list1.length != list2.length) return false;
  for (int i = 0; i < list1.length; i++) {
    if (list1[i] != list2[i]) return false;
  }
  return true;
}