cafe-utility 4.16.0 → 4.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +2 -0
- package/index.js +18 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ declare function onlyOrNull<T>(array: T[]): T | null;
|
|
|
13
13
|
declare function firstOrNull<T>(array: T[]): T | null;
|
|
14
14
|
declare function initializeArray<T>(count: number, initializer: (index: number) => T): T[];
|
|
15
15
|
declare function initialize2DArray<T>(x: number, y: number, initialValue: T): T[][];
|
|
16
|
+
declare function containsShape<T>(array2D: T[][], shape: T[][], x: number, y: number): boolean;
|
|
16
17
|
declare function takeRandomly<T>(array: T[], count: number): T[];
|
|
17
18
|
declare function pickRandomIndices<T>(array: T[], count: number): number[];
|
|
18
19
|
declare function pluck<T, K extends keyof T>(array: T[], key: K): T[K][];
|
|
@@ -311,6 +312,7 @@ export declare const Arrays: {
|
|
|
311
312
|
pickRandomIndices: typeof pickRandomIndices;
|
|
312
313
|
initialize: typeof initializeArray;
|
|
313
314
|
initialize2D: typeof initialize2DArray;
|
|
315
|
+
containsShape: typeof containsShape;
|
|
314
316
|
glue: typeof glue;
|
|
315
317
|
pluck: typeof pluck;
|
|
316
318
|
pick: typeof pick;
|
package/index.js
CHANGED
|
@@ -81,6 +81,23 @@ function initialize2DArray(x, y, initialValue) {
|
|
|
81
81
|
return array
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
function containsShape(array2D, shape, x, y) {
|
|
85
|
+
if (x < 0 || y < 0 || y + shape.length - 1 > array2D.length || x + shape[0].length - 1 > array2D[0].length) {
|
|
86
|
+
return false
|
|
87
|
+
}
|
|
88
|
+
for (let i = 0; i < shape.length; i++) {
|
|
89
|
+
for (let j = 0; j < shape[i].length; j++) {
|
|
90
|
+
if (shape[i][j] === undefined) {
|
|
91
|
+
continue
|
|
92
|
+
}
|
|
93
|
+
if (array2D[i + y][j + x] !== shape[i][j]) {
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return true
|
|
99
|
+
}
|
|
100
|
+
|
|
84
101
|
function takeRandomly(array, count) {
|
|
85
102
|
return shuffle(array).slice(0, count)
|
|
86
103
|
}
|
|
@@ -1810,6 +1827,7 @@ exports.Arrays = {
|
|
|
1810
1827
|
pickRandomIndices,
|
|
1811
1828
|
initialize: initializeArray,
|
|
1812
1829
|
initialize2D: initialize2DArray,
|
|
1830
|
+
containsShape,
|
|
1813
1831
|
glue,
|
|
1814
1832
|
pluck,
|
|
1815
1833
|
pick,
|