By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Re: Split Array

P: n/a
On 2008-10-14 03:06, dhtml wrote:
Evertjan. wrote:
>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))
....
>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))
....
var items = [4,5,6,1,2,3,4,8,5,9];
var newArray = items.slice(5,10).concat(items.slice(0,5));
....
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
Oct 14 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Oct 14, 4:52*pm, Conrad Lender <crlen...@yahoo.comwrote:
[...]
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
Oct 14 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.