The OpenD Programming Language

isSameLength

Checks if two or more ranges have the same number of elements. This function is optimized to always take advantage of the length member of either range if it exists.

If all ranges have a length member or at least one is infinite, _isSameLength's complexity is O(1). Otherwise, complexity is O(n), where n is the smallest of the lengths of ranges with unknown length.

Infinite ranges are considered of the same length. An infinite range has never the same length as a finite range.

bool
isSameLength
(
Ranges...
)
(
Ranges rs
)

Parameters

rs Ranges

two or more input ranges

Return Value

Type: bool

true if both ranges have the same length, false otherwise.

Examples

assert(isSameLength([1, 2, 3], [4, 5, 6]));
assert(isSameLength([1, 2, 3], [4, 5, 6], [7, 8, 9]));
assert(isSameLength([0.3, 90.4, 23.7, 119.2], [42.6, 23.6, 95.5, 6.3]));
assert(isSameLength("abc", "xyz"));
assert(isSameLength("abc", "xyz", [1, 2, 3]));

int[] a;
int[] b;
assert(isSameLength(a, b));
assert(isSameLength(a, b, a, a, b, b, b));

assert(!isSameLength([1, 2, 3], [4, 5]));
assert(!isSameLength([1, 2, 3], [4, 5, 6], [7, 8]));
assert(!isSameLength([0.3, 90.4, 23.7], [42.6, 23.6, 95.5, 6.3]));
assert(!isSameLength("abcd", "xyz"));
assert(!isSameLength("abcd", "xyz", "123"));
assert(!isSameLength("abcd", "xyz", "1234"));

Meta