Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6203477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:55:26+00:00 2026-05-24T04:55:26+00:00

Here is the software version number: "1.0", "1.0.1", "2.0", "2.0.0.1", "2.0.1" How can I

  • 0

Here is the software version number:

"1.0", "1.0.1", "2.0", "2.0.0.1", "2.0.1"

How can I compare this?

Assume the correct order is:

"1.0", "1.0.1", "2.0", "2.0.0.1", "2.0.1"

The idea is simple…:
Read the first digit, than, the second, after that the third…
But I can’t convert the version number to float number…
You also can see the version number like this:

"1.0.0.0", "1.0.1.0", "2.0.0.0", "2.0.0.1", "2.0.1.0"

And this is clearer to see what is the idea behind…
But, how can I convert it into a computer program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:55:28+00:00Added an answer on May 24, 2026 at 4:55 am

    The basic idea to make this comparison would be to use Array.split to get arrays of parts from the input strings and then compare pairs of parts from the two arrays; if the parts are not equal we know which version is smaller.

    There are a few of important details to keep in mind:

    1. How should the parts in each pair be compared? The question wants to compare numerically, but what if we have version strings that are not made up of just digits (e.g. “1.0a”)?
    2. What should happen if one version string has more parts than the other? Most likely “1.0” should be considered less than “1.0.1”, but what about “1.0.0”?

    Here’s the code for an implementation that you can use directly (gist with documentation):

    function versionCompare(v1, v2, options) {
        var lexicographical = options && options.lexicographical,
            zeroExtend = options && options.zeroExtend,
            v1parts = v1.split('.'),
            v2parts = v2.split('.');
    
        function isValidPart(x) {
            return (lexicographical ? /^\d+[A-Za-z]*$/ : /^\d+$/).test(x);
        }
    
        if (!v1parts.every(isValidPart) || !v2parts.every(isValidPart)) {
            return NaN;
        }
    
        if (zeroExtend) {
            while (v1parts.length < v2parts.length) v1parts.push("0");
            while (v2parts.length < v1parts.length) v2parts.push("0");
        }
    
        if (!lexicographical) {
            v1parts = v1parts.map(Number);
            v2parts = v2parts.map(Number);
        }
    
        for (var i = 0; i < v1parts.length; ++i) {
            if (v2parts.length == i) {
                return 1;
            }
    
            if (v1parts[i] == v2parts[i]) {
                continue;
            }
            else if (v1parts[i] > v2parts[i]) {
                return 1;
            }
            else {
                return -1;
            }
        }
    
        if (v1parts.length != v2parts.length) {
            return -1;
        }
    
        return 0;
    }
    

    This version compares parts naturally, does not accept character suffixes and considers “1.7” to be smaller than “1.7.0”. The comparison mode can be changed to lexicographical and shorter version strings can be automatically zero-padded using the optional third argument.

    There is a JSFiddle that runs “unit tests” here; it is a slightly expanded version of ripper234’s work (thank you).

    Important note: This code uses Array.map and Array.every, which means that it will not run in IE versions earlier than 9. If you need to support those you will have to provide polyfills for the missing methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure how to ask this question so here goes... Software sometimes says
Here are the two registry entries I'm asking about.** HKEY_LOCAL_MACHINE\Software\R-core\R\Current Version HKEY_LOCAL_MACHINE\Software\R-core\R\version\InstallPath When R
I used the same software used here http://us.gn.bartal.org/ to create a fixed width/height treemap
Hey all. I'm a professional software developer here in Seattle, WA USA. I program
Here's an interesting writeup of using eye tracking software to generate heat maps that
The in-house developed software where I work connects directly to a mysql server here
Does doing good enough software take anything from you being a programmer? Here are
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
Here is the code in a function I'm trying to revise. This example works
How do I track and manage the dependencies of software modules under version control?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.