0

here is my code and it work in all browser except IE 7 :

var sum = [0, 1, 2, 3, 4, 5, 6, 7, 8]
        .map(function (x) { return parseInt(input[x]) * (10 - x); })
        .reduce(function (x, y) { return x + y; }) % 11;

How I can resolve it to work in all browsers.

Edit: Error: Object doesn't support property or method 'map'

4
  • Which version of jquery are you using? Version 1.x supports older IE versions. Commented Sep 10, 2014 at 11:26
  • I've used [kendo]/[2014.1.416]/jquery.min.js which is 1.9.1 customized version for kendo Commented Sep 10, 2014 at 11:28
  • Error: Object doesn't support property or method 'map' Commented Sep 10, 2014 at 11:28
  • 2
    That is not Jquery map method ($.map), you are calling map method of native array. Commented Sep 10, 2014 at 11:30

1 Answer 1

1

You are calling map method of native array, and IE7 does not have it implemented (and the same happens with reduce). This is a solution using jQuery functions that should work:

var acc = 0;

$.each($.map([0, 1, 2, 3, 4, 5, 6, 7, 8], function(x) {
    return parseInt(input.charAt(x)) * (10 - x);
}), function(key, value) {
    acc = acc + value;
}); 

var sum = acc % 11;

Even more, if the keys of input are always numbers (and you go through all of them), you could remove the map function having the code like this:

var acc = 0;

$.each(input, function(key,value) {
    acc = acc + (parseInt(value) * (10 - key));
});

var sum = acc % 11;

Hope it helps.

Sign up to request clarification or add additional context in comments.

4 Comments

I know it doesn't support but your code returns 2 but the sum value for get and reduce function return 1 and actually it is different in result.
@kamiar3001 before I forgot to add the input[x] on that part of the code (I was using just X), so maybe that's why it is not working. What are the values in input so I can test it?
here is my string value "0453657941". it doesn't work again when it hit the compatibility button. the acc value is NaN but in IE 11 it work the same.
@kamiar3001 Edited answer, the problem was that you can not access the string elements with [] at IE7. With charAt should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.