Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Comparings strings #1085
See #1051 for duplicate issue.
Comparisions between strings was removed in v4 because people doing
Mathjs now tries for convert to number before making the comparison.
@josdejong maybe mathjs should allow people to compare strings using
Yes, we should indeed add a function
@harrysarson Good idea. I expect though that changing
I like the idea of introducing a
@josdejong you make a very good point about strings that are almost but not quite numbers.
I think it is much better for someone to try and compare two strings and get an error message than compare two nearly numbers and get false due to their typo and spend ages debugging for this.
I take back my string equality suggestion
It was a good suggestion, please keep them coming Harry :). It would have been the nicest solution but unfortunately there are some drawbacks.
I was thinking more about the
So maybe we should simply go for an
I've thought about it a bit more and I agree with Harry that we should go for the simple solution.
Let's implement two simple functions
I'm open to other naming of these functions.
It would work similar to
In fact, thinking about it, we can simply use
console.log(math.compare(2, 1)) // 1 console.log(math.compare(1, 1)) // 0 console.log(math.compare(1, 2)) // -1 console.log(math.compareNatural('B', 'A')) // 1 console.log(math.compareNatural('A', 'A')) // 0 console.log(math.compareNatural('A', 'B')) // -1