Reputation: 101
I've been using this line of code to match these two arrays so they have the same amount of data.
var items = viewModel.Date1;
var items2 = viewModel.Date2;
items = items2.map( row =>
//is there a matching row in items?
items.filter( r => r.theString == row.theString).length == 0 ?
//if not, fill with zeros
{theString:0, theCount:0} :
//if there is, return the items' row
items.filter( r => r.theString == row.theString)[0] );
In IE, using =>
gives me a Syntax error.
How do I rewrite this so it works in Firefox, Chrome, and IE?
Upvotes: 3
Views: 1627
Reputation: 1905
arrow function
r => r.theString == row.theString[0]
change to
function(r) { r.theString == row.theString[0] }
Upvotes: 1
Reputation: 1378
http://caniuse.com/#feat=arrow-functions
Arrow functions are not yet in IE.
You would be best running your code through a JS compiler like Babel, http://babeljs.io/
Upvotes: 2