I was surprised to find that the $.map
function of jQuery is defined to:
.. returned array will be flattened into the resulting array.
What should I do if I don't want that behavior, but rather to get an array-of-arrays as the product?
Likely, I will resort to $.each
.
Here's code to show what I expected (coming from Scala, where map
and flatMap
are separate.
var arr= [1,2,3];
var brr= $.map( arr, function(el) {
return [-el, Math.log(el)];
} );
// 'brr' is: [-1, 0, -2, 0.6931471805599453, -3, 1.0986122886681098]
// I expected: [[-1, 0], [-2, 0.6931471805599453], [-3, 1.0986122886681098]]