Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"sameness" in the context of mutability
type RationalNumber = [number /* numerator */, number /* denominator */];
// turn into decimal form before comparing in order to reduce fraction
const isEqual = (a: RationalNumber, b: RationalNumber) => (a[0] / a[1]) === (b[0] / b[1]);
const r1: RationalNumber = [2, 3];
const r2: RationalNumber = [2, 3];
const r3: RationalNumber = [2, 5];
r2[1] = 5;
isEqual(r1, r2); // => false
isEqual(r2, r3); // => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.