Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30276
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2016-04-14 09:53 -0700 |
| References | <ea578169-9d58-4249-91b4-e0cbad5a6fd8@googlegroups.com> <nen4e4$ggn$1@dont-email.me> |
| Message-ID | <5f64116c-3f44-4eb6-b178-160beb37efaa@googlegroups.com> (permalink) |
| Subject | Re: duplicator an array |
| From | JRough <janis.rough@gmail.com> |
On Wednesday, April 13, 2016 at 9:00:18 PM UTC-7, Aleksandro wrote:
> On 13/04/16 22:27, JRough wrote:
> >
> > I have one question for you.
> > The problem is to create a duplicator function like below. To make this one work:
> > [1,2,3,4,5].duplicator();
> > ------------------------
> > Okay, first thing i did was just get it to work in a regular function. I think this works because I saw the duplcation of res in Firebug.
> > var arr =[1,2,3,4,5];
> > function duplicator(arr){
> > return arr.concat(arr.slice(0));
> > }
> > var res = duplicator(arr);
> > console.log(res.toString());
> > The only problem with this one is it doesn't output the string in the console.log.
> > Do you know why?
>
> It works perfectly for me.
I can't see it in firebug scratchpad console.log I'll try it in chrome tnx
>
> > Okay, supposing the above works then I thought I would make an anonymous function in the duplicator method. This would make it work the way the problem was first outlined above. The only problem is how do I capture the value of the two arrays?
> >
> >
> > I guess you would do something like Array.prototype.duplicator = (function (){
> > return this.concat(arr.slice(0));
> > })()
>
> Try:
>
> Array.prototype.duplicate = function ()
> {
> this.push.apply(this, this.slice(0))
> }
tnx again
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
duplicator an array JRough <janis.rough@gmail.com> - 2016-04-13 18:27 -0700
Re: duplicator an array Aleksandro <aleksandro@gmx.com> - 2016-04-14 01:00 -0300
Re: duplicator an array JRough <janis.rough@gmail.com> - 2016-04-14 09:53 -0700
Re: duplicator an array "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-04-14 19:41 +0200
Re: duplicator an array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-14 22:09 +0200
Re: duplicator an array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-14 22:23 +0200
Re: duplicator an array Stefan Weiss <krewecherl@gmail.com> - 2016-04-16 14:27 +0200
Re: duplicator an array Joao Rodrigues <jr@none.com> - 2016-04-16 12:01 -0300
Re: duplicator an array Joao Rodrigues <jr@none.com> - 2016-04-16 13:43 -0300
Re: duplicator an array Aleksandro <aleksandro@gmx.com> - 2016-04-16 14:13 -0300
Re: duplicator an array bharat.bandgar009@gmail.com - 2017-05-03 01:33 -0700
csiph-web