Ben Bacarisse
9/16/2015 3:03:00 PM
pinapalmieri@gmail.com writes:
> If I have two array:
>
> arr1 = "Bananas", "Kiwi", "Mixed nuts" and
> arr2 = 8,3,1
>
> how i can create the following structure data?
>
> ['Bananas', 8],
> ['Kiwi', 3],
> ['Mixed nuts', 1]
You are missing lots of []s. You have
var arr1 = ["Bananas", "Kiwi", "Mixed nuts"];
var arr2 = [8, 3, 1];
and you want
[ [ 'Bananas', 8 ],
[ 'Kiwi', 3 ],
[ 'Mixed nuts', 1 ] ]
> Any suggestions?
What have you tried so far? Do you have any constraints on the
potability of the solution? Is this coursework?
Maybe
Array.prototype.zip = function (a) {
return this.map(function (e, i) {return [e, a[i]]; });
};
does what you want.
--
Ben.