1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function insertIntoList(targetListArg, toInsert, offset) {
|
17 | var targetList = targetListArg;
|
18 |
|
19 | if (offset === targetList.count()) {
|
20 | toInsert.forEach(function (c) {
|
21 | targetList = targetList.push(c);
|
22 | });
|
23 | } else if (offset === 0) {
|
24 | toInsert.reverse().forEach(function (c) {
|
25 | targetList = targetList.unshift(c);
|
26 | });
|
27 | } else {
|
28 | var head = targetList.slice(0, offset);
|
29 | var tail = targetList.slice(offset);
|
30 | targetList = head.concat(toInsert, tail).toList();
|
31 | }
|
32 |
|
33 | return targetList;
|
34 | }
|
35 |
|
36 | module.exports = insertIntoList; |
\ | No newline at end of file |