Files
Noja/examples/json/utils.noja
T

38 lines
782 B
Plaintext

fun compareAny(A, B) {
fun compareLists(A: List, B: List) {
n = count(A);
if n != count(B):
return false;
i = 0;
while i < n: {
if not compareAny(A[i], B[i]):
return false;
i = i + 1;
}
return true;
}
T = type(A);
if T != type(B):
return false;
if T == List:
return compareLists(A, B);
if T == Map:
error("Maps aren't supported yet!");
return A == B;
}
assert(compareAny(1, 2) == false);
assert(compareAny([], []) == true);
assert(compareAny([], [1]) == false);
assert(compareAny([1, 2, 3], [1, 2, 3]) == true);
assert(compareAny([1, 2, 3], [1, 2, 4]) == false);
assert(compareAny([1, 2, 3], [1, 2, 3, 4]) == false);