Last active
September 18, 2019 16:24
-
-
Save jbmilgrom/47780d87d0f8f56932ebb2978de12815 to your computer and use it in GitHub Desktop.
"sameness" in the context of immutability
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 = 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