Re: Split Array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Conrad Lender

    Re: Split Array

    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 .slice(0,5))
    ....
    var items = [4,5,6,1,2,3,4,8 ,5,9];
    var newArray = items.slice(5,1 0).concat(items .slice(0,5));
    ....
    var items = [4,5,6,1,2,3,4,8 ,5,9];
    var start = items.slice(5);
    start.push.appl y(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 ;-)



    - Conrad
  • RobG

    #2
    Re: Split Array

    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

    Comment

    Working...