Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28694

Re: structure data : array

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: structure data : array
Date 2015-09-16 16:02 +0100
Organization A noiseless patient Spider
Message-ID <87lhc6e7a8.fsf@bsb.me.uk> (permalink)
References <39d7a0ae-6b71-44a9-83eb-0e46928d6be3@googlegroups.com>

Show all headers | 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


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