@@ 352-377 (lines=26) @@ | ||
349 | moveToBottom: function(slot, returnNew = false){ |
|
350 | var list = this; |
|
351 | ||
352 | if (returnNew){ |
|
353 | ||
354 | // ALWAYS RETURNS NEW ARRAY |
|
355 | ||
356 | // exit quickly if slot not in array |
|
357 | var al = list.length; |
|
358 | if (slot < 0 || slot >= al) { |
|
359 | return list.concat(); |
|
360 | } |
|
361 | ||
362 | // create new array with slot on top |
|
363 | var newArr = []; |
|
364 | var n = 0; |
|
365 | ||
366 | // add all other slots |
|
367 | for (var a = 0;a<al;a++){ |
|
368 | if (a != slot) { |
|
369 | newArr[n++] = list[a]; |
|
370 | } |
|
371 | } |
|
372 | ||
373 | // add slot to bottom |
|
374 | newArr[n++] = list[slot]; |
|
375 | return newArr; |
|
376 | ||
377 | } |
|
378 | ||
379 | // MODIFIES ARRAY IN PLACE |
|
380 | ||
@@ 311-333 (lines=23) @@ | ||
308 | moveToTop: function(slot, returnNew = false){ |
|
309 | var list = this; |
|
310 | ||
311 | if (returnNew){ |
|
312 | ||
313 | // ALWAYS RETURNS NEW ARRAY |
|
314 | ||
315 | // exit quickly if slot not in array |
|
316 | var al = list.length; |
|
317 | if (slot < 0 || slot >= al) { |
|
318 | return list.concat(); |
|
319 | } |
|
320 | ||
321 | // create new array with slot on top |
|
322 | var newArr = [list[slot]]; |
|
323 | var n = 1; |
|
324 | ||
325 | // add all other slots |
|
326 | for (var a = 0;a<al;a++){ |
|
327 | if (a != slot) { |
|
328 | newArr[n++] = list[a]; |
|
329 | } |
|
330 | } |
|
331 | ||
332 | return newArr; |
|
333 | } |
|
334 | ||
335 | ||
336 | // MODIFIES ARRAY IN PLACE |