We help IT Professionals succeed at work.

Translate Java code in javascript

matthew016
matthew016 asked
on
710 Views
Last Modified: 2008-01-09
Hello,

is it possible to translate this snap of code into Javascript ?

The method checks wether an isin code (string) is correct or not :

      public boolean validIsin(String src) {
            int s = 0;
            int a = (src.length() == 12) ? 1 : 2;
            for (int i = src.length() - 1; i >= 0; i--) {
                  int c = src.charAt(i);
                  if (c > '9') {
                        c -= ('A' - 10);
                        s += (3 - a) * (c / 10) + a * c + (a - 1) * (c % 10) / 5;
                  } else {
                        c -= '0';
                        s += a * c + (a - 1) * (c / 5);
                        a = 3 - a;
                  }
            }
            s %= 10;
            return ((10 - s % 10) % 10) == 0;
      }

Must return true for the following strings :
US0378331005
AU0000XVGZA3
GB0002634946
Should return false if you modify some numbers in the above strings.

Thank you for any help.
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
You should probably tag this with Java as well.

Author

Commented:
thanks, works great,
what do you mean tag this with java ?
I mean add the "Java" tag to your question so it's easier for others to find later.  Your question requires familiarity with both Java and Javascript.

It may not be possible to change the tags after the question is posted.  If that is the case, you can post a request in the Community boards for one of the admins to change the tags.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.