-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comparings strings #1085
Comments
The documentation says the following:
This behavior is kind of surprising I have to say. @josdejong: Is there a string comparison function? So far I haven't found one, if there isn't it might be a good addition. |
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 editedClarified |
On one hand I like the idea of having an But there needs to be a way to do string comparisons either way! |
Sorry, I meant |
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 |
The two different equals operators in js lead to a fair bit of cunfusion, I would definately argue for keeping things simple in mathjs and sticking to I much prefer the idea of 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. |
Would compareText return -1,0 or 1 based on the comparison? |
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 |
I've implemented functions |
when I use string formula , the error is shown, I attached image for this error
The text was updated successfully, but these errors were encountered: