// floating point precision function approximatelyEqual(a, b) { // If inputs are arrays, compare each element if (Array.isArray(a) && Array.isArray(b)) {
assertEq(a.length, b.length); // Compare each element for (let i = 0; i < a.length; i++) {
approximatelyEqual(a[i], b[i]);
} returntrue;
}
// For single numbers var r = (a != a && b != b) || Math.abs(a - b) < 0.001; if (!r) {
print('Got', a, ', to be approximately equal to', b);
assertEq(false, true);
} returntrue;
}
// this value is a valid iterator object from another compartment const g = newGlobal({ newCompartment: true }); const localIterator = Iterator.range(0, 10); const otherIterator = g.eval("Iterator.range(0, 10)");
const result = localIterator.next.call(otherIterator);
// test with an option object const options = Iterator.range(0, Infinity, { step: 3 });
assertEq(options.next().value, 0);
assertEq(options.next().value, 3);
assertEq(options.next().value, 6);
// test that inclusive end is ignored for infinite ranges const infiniteRangeInclusive = Iterator.range(0, Infinity, { inclusiveEnd: true });
assertEq(infiniteRangeInclusive.next().value, 0);
assertEq(infiniteRangeInclusive.next().value, 1);
// test negative infinity with inclusive end const negativeInfiniteRangeInclusive = Iterator.range(0, -Infinity, -1, { inclusiveEnd: true });
assertEq(negativeInfiniteRangeInclusive.next().value, 0);
assertEq(negativeInfiniteRangeInclusive.next().value, -1);
assertEq(negativeInfiniteRangeInclusive.next().value, -2);
// test negative infinity with step and inclusive end const negativeInfiniteRangeStepInclusive = Iterator.range(0, -Infinity, -2, { inclusiveEnd: true });
assertEq(negativeInfiniteRangeStepInclusive.next().value, 0);
assertEq(negativeInfiniteRangeStepInclusive.next().value, -2);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.