Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28694
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: structure data : array |
| Date | Wed, 16 Sep 2015 16:02:55 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 39 |
| Message-ID | <87lhc6e7a8.fsf@bsb.me.uk> (permalink) |
| References | <39d7a0ae-6b71-44a9-83eb-0e46928d6be3@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="18001"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18TQZ78Pe6Y1/6aY0+FIBZ/y8O5U4Xb+S4=" |
| Cancel-Lock | sha1:dQ/629IBA3dEVIbx+oLl56r5cPM= sha1:x5xBhRHQl1qO32UCJyyCwkbGGws= |
| X-BSB-Auth | 1.4795d4f3e61d023d1286.20150916160255BST.87lhc6e7a8.fsf@bsb.me.uk |
| Xref | csiph.com comp.lang.javascript:28694 |
Show key headers only | View raw
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.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
structure data : array pinapalmieri@gmail.com - 2015-09-16 07:42 -0700
Re: structure data : array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-16 16:02 +0100
Re: structure data : array "Bruce M. Axtens" <bugmagnet@outlook.com> - 2015-09-16 23:17 +0800
Re: structure data : array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-16 16:23 +0100
Re: structure data : array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-09-16 22:00 +0200
csiph-web