MCPcopy Index your code
hub / github.com/angular/angular / arrayInsert2

Function arrayInsert2

packages/core/src/util/array_utils.ts:132–153  ·  view source on GitHub ↗
(array: any[], index: number, value1: any, value2: any)

Source from the content-addressed store, hash-verified

130 * @param value2 Value to add to array.
131 */
132export function arrayInsert2(array: any[], index: number, value1: any, value2: any): void {
133 ngDevMode && assertLessThanOrEqual(index, array.length, "Can't insert past array end.");
134 let end = array.length;
135 if (end == index) {
136 // inserting at the end.
137 array.push(value1, value2);
138 } else if (end === 1) {
139 // corner case when we have less items in array than we have items to insert.
140 array.push(value2, array[0]);
141 array[0] = value1;
142 } else {
143 end--;
144 array.push(array[end - 1], array[end]);
145 while (end > index) {
146 const previousEnd = end - 2;
147 array[end] = array[previousEnd];
148 end--;
149 }
150 array[index] = value1;
151 array[index + 1] = value2;
152 }
153}
154
155/**
156 * Get an index of an `value` in a sorted `array`.

Callers 3

expectArrayInsert2Function · 0.90
addToQueueMethod · 0.90
keyValueArraySetFunction · 0.85

Calls 2

assertLessThanOrEqualFunction · 0.90
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…