Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old October 14th, 2008, 07:55 AM
Conrad Lender
Guest
 
Posts: n/a
Default Re: Split Array

On 2008-10-14 03:06, dhtml wrote:
Quote:
Evertjan. wrote:
Quote:
>var oldArray = [4,5,6,1,2,3,4,8,5,9];
>var newArray = oldArray.slice(5,10);
>newArray = newArray.concat(oldArray.slice(0,5))
....
Quote:
Quote:
>var oldArray = [4,5,6,1,2,3,4,8,5,9];
>var newArray = [];
>newArray = newArray.concat(oldArray.slice(5,10),oldArray.slic e(0,5))
....
Quote:
var items = [4,5,6,1,2,3,4,8,5,9];
var newArray = items.slice(5,10).concat(items.slice(0,5));
....
Quote:
var items = [4,5,6,1,2,3,4,8,5,9];
var start = items.slice(5);
start.push.apply(start, items.slice(0,5));
JFTR, all of these would require an additional loop to find the index of
the element with the value 3. "There's more than one way to do it"...
looks like we'll have a Javascript Golf Apocalypse soon ;-)
http://en.wikipedia.org/wiki/Perl_Golf_Apocalypse


- Conrad
  #2  
Old October 15th, 2008, 12:15 AM
RobG
Guest
 
Posts: n/a
Default Re: Split Array

On Oct 14, 4:52*pm, Conrad Lender <crlen...@yahoo.comwrote:
[...]
Quote:
JFTR, all of these would require an additional loop to find the index of
the element with the value 3.
If that was a requirement, yes. *But* the OP didn't say how the index
used to split the array was chosen, only that for the example it was
from the element with value 3 (i.e. index 5).


--
Rob
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles