@@ 608-633 (lines=26) @@ | ||
605 | moveToBottom: function(slot, returnNew = false){ |
|
606 | var list = this; |
|
607 | ||
608 | if (returnNew){ |
|
609 | ||
610 | // ALWAYS RETURNS NEW ARRAY |
|
611 | ||
612 | // exit quickly if slot not in array |
|
613 | var al = list.length; |
|
614 | if (slot < 0 || slot >= al) { |
|
615 | return list.concat(); |
|
616 | } |
|
617 | ||
618 | // create new array with slot on top |
|
619 | var newArr = []; |
|
620 | var n = 0; |
|
621 | ||
622 | // add all other slots |
|
623 | for (var a = 0;a<al;a++){ |
|
624 | if (a != slot) { |
|
625 | newArr[n++] = list[a]; |
|
626 | } |
|
627 | } |
|
628 | ||
629 | // add slot to bottom |
|
630 | newArr[n++] = list[slot]; |
|
631 | return newArr; |
|
632 | ||
633 | } |
|
634 | ||
635 | // MODIFIES ARRAY IN PLACE |
|
636 | ||
@@ 567-589 (lines=23) @@ | ||
564 | moveToTop: function(slot, returnNew = false){ |
|
565 | var list = this; |
|
566 | ||
567 | if (returnNew){ |
|
568 | ||
569 | // ALWAYS RETURNS NEW ARRAY |
|
570 | ||
571 | // exit quickly if slot not in array |
|
572 | var al = list.length; |
|
573 | if (slot < 0 || slot >= al) { |
|
574 | return list.concat(); |
|
575 | } |
|
576 | ||
577 | // create new array with slot on top |
|
578 | var newArr = [list[slot]]; |
|
579 | var n = 1; |
|
580 | ||
581 | // add all other slots |
|
582 | for (var a = 0;a<al;a++){ |
|
583 | if (a != slot) { |
|
584 | newArr[n++] = list[a]; |
|
585 | } |
|
586 | } |
|
587 | ||
588 | return newArr; |
|
589 | } |
|
590 | ||
591 | ||
592 | // MODIFIES ARRAY IN PLACE |