-2

What does (a=>) do in the context below?

function findOutlier(int){
  var even = int.filter(a=>a%2==0);
  var odd = int.filter(a=>a%2!==0);
  return even.length==1? even[0] : odd[0];
}
EFH
  • 431
  • 1
  • 6
  • 14
  • 1
    Those are [arrow functions.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) I'd suggest reading [this question](http://stackoverflow.com/questions/34361379/arrow-function-vs-function-declaration-expressions-are-they-equivalent-exch) to get a good feel for them. – Mike Cluck Mar 25 '16 at 21:57

1 Answers1

0

Those are called fat arrow functions. In this case, it's the same as

int.filter(function(a){ return a%2==0});

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217