MCPcopy Create free account
hub / github.com/denoland/std / insert

Method insert

data_structures/unstable_2d_array.ts:277–290  ·  view source on GitHub ↗

* Insert another 2d array at specific coordinates. * If the inserted 2d array is greater than the 2d array this method is called on, * the inserted value will be trimmed to fit the current 2d array. * * @example Usage * ```ts * import { D2Array } from "@std/data-structures/unstable

(x: number, y: number, value: readonly T[][] | D2Array<T>)

Source from the content-addressed store, hash-verified

275 * @param value The 2d array to insert at the provided coordinates.
276 */
277 insert(x: number, y: number, value: readonly T[][] | D2Array<T>) {
278 if (value instanceof D2Array) {
279 value = value.raw;
280 }
281
282 for (let i = y; i < Math.min(this.raw.length, y + value.length); i++) {
283 const thisRow = this.raw[i]!;
284 const valueRow = value[i - y]!;
285
286 for (let j = x; j < Math.min(thisRow.length, x + valueRow.length); j++) {
287 thisRow[j] = valueRow[j - x]!;
288 }
289 }
290 }
291
292 /**
293 * The width of the 2d array.

Callers 5

setTimerFunction · 0.45
nowMethod · 0.45

Calls 1

minMethod · 0.80

Tested by

no test coverage detected