locked
How to calculate the difference count between two sequential alphanumeric 13 characters serial numbers 234CFG03DQ101, 234CFG03DQ106 =5 RRS feed

  • Question

  • User-695697013 posted

    <br>
    How to calculate the difference count between two sequential alphanumeric 13 characters serial numbers 234CFG03DQ101, 234CFG03DQ106 =5 using JavaScript<br>
    Saturday, February 3, 2018 11:10 AM

Answers

  • User-695697013 posted

    Thanks, A2H   the Alphanumeric series  can have any number digits. I used the match  js function to grep me all last digts....

    var alphanum1 = "234CFG03DQ101";
    //Get the last 3 digits
    var num1 = alphanum1.match("[0-9]+$");

    var alphanum2 = "234CFG03DQ106";
    //Get the last 3 digits
    var num2 = alphanum2.match("[0-9]+$");
    //Calculate difference
    var result = parseInt(num2) - parseInt(num1);
    alert(result);

    Sample link

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 6, 2018 10:42 AM

All replies

  • User2103319870 posted

    How to calculate the difference count between two sequential alphanumeric 13 characters serial numbers 234CFG03DQ101, 234CFG03DQ106 =5 using JavaScript

    if you have numbers always in the format i.e last 3 will be of numbers then you can use below code to calculate the differernce

    var alphanum1 = "234CFG03DQ101";
    //Get the last 3 digits
    var num1 = alphanum1.slice(-3);
    
    var alphanum2 = "234CFG03DQ106";
    //Get the last 3 digits
    var num2 = alphanum2.slice(-3);
    //Calculate difference
    var result = parseInt(num2) - parseInt(num1);
    alert(result);
    Saturday, February 3, 2018 7:21 PM
  • User-1838255255 posted

    Hi balasv,

    According to your description and needs, i make a sample use javascript, these are the steps of how to achieve this goal: 

    1. Get all numbers from the 13 characters. 
    2. Then use Math.abs to get the value of |a-b|. 

    For more details, please check the following sample code:

     <script>
            debugger;
            var data1 = "234CFG03DQ101";
            var data2 = "234CFG03DQ106";
    
            var newdata1 = "";
            var newdata2 = "";
    
            for (var i = 0; i < data1.length; i++) {
                if (isNaN(data1[i])) {
                } else {
                    newdata1 += data1[i]
                }
            }
    
            for (var i = 0; i < data2.length; i++) {
                if (isNaN(data2[i])) {
                } else {
                    newdata2 += data2[i]
                }
            }
    
            var amount = 0;
            for (var i = 0; i < newdata1.length; i++) {
                var data = Math.abs(newdata1[i] - newdata2[i]);
                amount += data;
            }
            alert("Difference Count is: " + amount);
    </script>

    Best Regards,

    Eric Du 

    Tuesday, February 6, 2018 2:21 AM
  • User-695697013 posted

    Thanks, A2H   the Alphanumeric series  can have any number digits. I used the match  js function to grep me all last digts....

    var alphanum1 = "234CFG03DQ101";
    //Get the last 3 digits
    var num1 = alphanum1.match("[0-9]+$");

    var alphanum2 = "234CFG03DQ106";
    //Get the last 3 digits
    var num2 = alphanum2.match("[0-9]+$");
    //Calculate difference
    var result = parseInt(num2) - parseInt(num1);
    alert(result);

    Sample link

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 6, 2018 10:42 AM