Skip to content

Instantly share code, notes, and snippets.

@jbmilgrom
Last active September 18, 2019 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbmilgrom/cc687ca43a9f51d5ba5c1ae26f74728f to your computer and use it in GitHub Desktop.
Save jbmilgrom/cc687ca43a9f51d5ba5c1ae26f74728f to your computer and use it in GitHub Desktop.
"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