LeJared LeJared 2, 1 1 gold badge 16 16 silver badges 28 28 bronze badges. Failed with '0. See fiddle: jsfiddle. It outputs ["0. I agree this is an usual point. I'm using this with github. Parent: 0. See this issue for more details on why I care: github. See answer here stackoverflow. Older browsers used to guess the radix parameter if not specified. A leading zero in a number string like the middle part in "1. Arthur Ronconi Arthur Ronconi 1, 21 21 silver badges 18 18 bronze badges. I often need to know if it's newer or the same, so my code can decide whether to hide a feature that is not supported.
Isn't that the question that most are interested in? Nice and short, exactly what I was looking for. You could also add oldVer. The simplest is to use localeCompare : a. Chris 1, 1 1 gold badge 18 18 silver badges 34 34 bronze badges.
Idan Idan 2, 20 20 silver badges 30 30 bronze badges. That's the simplest answer, loving it! Why doesn't this have more votes? Is there anything wrong with it? It seems to pass all the tests I wrote. JuanMendes Simple answer, I wrote this 10 years after post the question : but it's a great idea, let's start voting! JuanMendes This does have a limitation that the version strings must always have the same number of parts. So when passed 1.
Mordred That's the behavior I expect, I don't expect those to be treated the same. See semver. Show 1 more comment. Simple, but limited to three version fields. Realise I'm coming to this late, but I really like this simple solution for semantic versioning because three version fields is what you'll have.
Finally a version I can read easily. Yes, three version fields is the standard so this is useful to most of us — Juan Mendes. Pros: Handles version strings of arbitrary length. Compare numbers not strings. Not false. Don't waste time on useless compares in the loop.
Cons: It does not handle letters in the version string. I don't know how that would even work? Viktor Viktor 5 5 silver badges 11 11 bronze badges. This function is prone to code injection if the comparator parameter is used with unchecked user input!
Example: compareVersions '1. LeJared True. When I wrote it we were not going to use it with user submitted code though. Should have brought it up as a con probably. I have now updated the code to eliminate that possibility. Now though, when webpack and other node.
The core of the lib: module. Good, then you can use substring instead of padStart for better compatibility i. Awesome Dev Awesome Dev 61 1 1 silver badge 4 4 bronze badges. The regex is unnecessary. You can simply append. Forgive me if this idea already been visited in a link I have not seen. Pow 10, 0 ; Which made comparisons very easy comparing a double. Noxin Noxin 51 1 1 silver badge 1 1 bronze badge. This will break, if this. Ally Ally 4, 5 5 gold badges 33 33 silver badges 41 41 bronze badges.
GorvGoyl GorvGoyl 30k 22 22 gold badges silver badges bronze badges. You could use String localeCompare with options sensitivity Which differences in the strings should lead to non-zero result values. Possible values are: "base" : Only strings that differ in base letters compare as unequal. Other differences may also be taken into consideration. Community Bot 1 1 1 silver badge. Nina Scholz Nina Scholz k 22 22 gold badges silver badges bronze badges.
How does this actually work? What is the undefined above, Language? How come you manage to post this while I read the others ; — mplungjan. Herohtar 4, 3 3 gold badges 29 29 silver badges 36 36 bronze badges. Marc Marc 29 4 4 bronze badges. Epic answer, exactly what I was looking for. Dyllan M Dyllan M 1 1 silver badge 13 13 bronze badges.
Welcome to SO. This question has a lot of good answers already, please refrain from adding new answers unless you add something new. Sid Vishnoi Sid Vishnoi 1, 1 1 gold badge 13 13 silver badges 27 27 bronze badges. Sascha Galley Sascha Galley David David 11 2 2 bronze badges.
Anyway, I keep my answer here This one will also fail as most of variants around in these cases: versionCompare '1. More complicated solutions might require an in-person walk through, whereas other software might be intuitive and only require documentation.
Choose the best option for your team. Software customer service and support: Everyone wants software with stellar customer service, but how do you want to receive that support? Software features: Pending on industry, various software products offer a common set of features.
Remember: You might not need every feature a system offers. Integration can reduce adoption headaches down the road, but be sure to ask the vendor about security risks for data transfer between solutions.
Software users: How many people are going to use the system you choose? Step 2: Enter the information you collected above into our software comparison template This software comparison template is in Excel format. Need more help choosing software for your business?
About the Author. I appreciate your article here. I found it very helpful. Thank you so much! Comment Guidelines: All comments are moderated before publication and must meet our guidelines. Largest palindrome not exceeding N which can be expressed as product of two 3-digit numbers. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Most popular in Strings. More related articles in Strings.
We use cookies to ensure you have the best browsing experience on our website.
0コメント