Last active
September 18, 2019 16:21
-
-
Save jbmilgrom/cc687ca43a9f51d5ba5c1ae26f74728f to your computer and use it in GitHub Desktop.
"sameness" in the context of mutability
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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