Skip to content

Instantly share code, notes, and snippets.

@jbmilgrom
Last active September 18, 2019 16:24
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/47780d87d0f8f56932ebb2978de12815 to your computer and use it in GitHub Desktop.
Save jbmilgrom/47780d87d0f8f56932ebb2978de12815 to your computer and use it in GitHub Desktop.
"sameness" in the context of immutability
type RationalNumber = readonly [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];
isEqual(r1, r2); // => true
isEqual(r1, r3); // => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment