[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

structure data : array

pinapalmieri

9/16/2015 2:43:00 PM

Hi,


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]



Any suggestions?


thanks,


Giusy


4 Answers

Ben Bacarisse

9/16/2015 3:03:00 PM

0

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.

Bruce M. Axtens

9/16/2015 3:17:00 PM

0

On Wed, 16 Sep 2015 23:02:55 +0800, Ben Bacarisse <ben.usenet@bsb.me.uk>
wrote:

> What have you tried so far? Do you have any constraints on the
> potability of the solution?

I'll drink to that!


--
Using Opera's mail client: http://www.opera...

Ben Bacarisse

9/16/2015 3:23:00 PM

0

"Bruce M. Axtens" <bugmagnet@outlook.com> writes:

> On Wed, 16 Sep 2015 23:02:55 +0800, Ben Bacarisse
> <ben.usenet@bsb.me.uk> wrote:
>
>> What have you tried so far? Do you have any constraints on the
>> potability of the solution?
>
> I'll drink to that!

Obviously I already have!

--
Ben.

Thomas 'PointedEars' Lahn

9/16/2015 8:00:00 PM

0

Ben Bacarisse wrote:

> 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?
>> [â?¦]
>> Any suggestions?
>
> What have you tried so far? Do you have any constraints on the
> potability of the solution?

*g*

> Is this coursework?

What else could it be? In my experience, people ending their postings with
â??Any hints?â? or â??Any suggestions?â? are like black holes for your free time,
and thus it is a waste of that precious commodity to reply to them with
anything other than <http://www.catb.org/~esr/faqs/smart-question..., if
at all.

The percentage among those people who anonymously post viathe buggy Google
Groups interface is particularly high, which is also why I do not read
postings injected into Usenet via that, by default.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.