-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatrixSlice.js
50 lines (38 loc) · 1.45 KB
/
matrixSlice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import {
getFirstElement,
getLastElement,
getAllButFirstElement,
getAllButLastElement,
getMiddleElements
} from "./arrayUtils";
import { doColumnOperation } from "./matrixDecorators";
// Slice rows from matrix
export const sliceMatrixRows = (mtx, startIndex, stopIndex) => {
if (stopIndex === undefined) {
return mtx.slice(startIndex);
} else {
return mtx.slice(startIndex, stopIndex);
}
};
// Get top row from matrix
export const getTopRow = mtx => [getFirstElement(mtx)];
// Get all but top row from matrix
export const getAllButTopRow = mtx => getAllButFirstElement(mtx);
// Get bottom row from matrix
export const getBottomRow = mtx => [getLastElement(mtx)];
// Get all but bottom row from matrix
export const getAllButBottomRow = mtx => getAllButLastElement(mtx);
// Get middle rows from matrix
export const getMiddleRows = mtx => getMiddleElements(mtx);
// Slice columns from matrix
export const sliceMatrixCols = doColumnOperation(sliceMatrixRows);
// get left column from matrix
export const getLeftCol = doColumnOperation(getTopRow);
// get all but the left column from matrix
export const getAllButLeftCol = doColumnOperation(getAllButTopRow);
// get right column from matrix
export const getRightCol = doColumnOperation(getBottomRow);
// get all but right column from matrix
export const getAllButRightCol = doColumnOperation(getAllButBottomRow);
// get middle rows from matrix
export const getMiddleCols = doColumnOperation(getMiddleRows);