2djs 中文文档教程
2djs
JavaScript 库二维数组。
- Install
- API
constructor
get()
stat()
clear()
rowSize()
columnSize()
at(rowPosition, columnPosition)
row(position)
column(position)
rows()
columns()
firstRow()
firstColumn()
lastRow()
lastColumn()
add(twoDimensionalArray)
addRow(row)
addColumn(column)
isMember(item)
- License
Install
npm install --save 2djs
或者,
yarn add 2djs
API
constructor
import TwoDimensionalArray from '2djs';
const items = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
];
const array = new TwoDimensionalArray(items);
get()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.get(); // [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12] ]
stat()
console.log(array.stats());
{
rowSize: 3,
columnSize: 4
};
clear()
array.clear(); // []
rowSize()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.rowSize(); // 3
columnSize()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.columnSize(); // 4
at(rowPosition, columnPosition)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.at(0, 0); // 1
array.at(2, 2); // 11
array.at(10000, 0); // null
row(position)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.row(0); // [1, 2, 3, 4]
array.row(2); // [9, 10, 11, 12]
column(position)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.column(0); // [1, 5, 9]
array.column(2); // [3, 7, 11]
rows()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.rows(); // [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ]
columns()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.columns(); // [ [ 1, 5, 9 ], [ 2, 6, 10 ], [ 3, 7, 11 ], [ 4, 8, 12 ] ]
firstRow()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.firstRow(); // [1, 2, 3, 4]
firstColumn()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.firstColumn(); // [1, 5, 9]
lastRow()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.lastRow(); // [9, 10, 11, 12]
lastColumn()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.lastColumn(); // [4, 8, 12]
add(twoDimensionalArray)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
const arr = [ [13, 14, 15, 16], [17, 18, 19, 20] ];
array.add(arr); // [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11, 12 ], [ 13, 14, 15, 16 ], [ 17, 18, 19, 20 ] ]
addRow(row)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.addRow([13, 14, 15, 16]); // [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11, 12 ], [ 13, 14, 15, 16 ] ]
addColumn(column)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.addColumn([2, -1, 1]); // [ [ 1, 2, 3, 4, 2 ], [ 5, 6, 7, 8, -1 ], [ 9, 10, 11, 12, 1 ] ]
isMember(item)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.isMember(1); // true
array.isMember(1000); // false
License
版权所有 (c) 2020 kenju
,根据 Apache 许可证 2.0 版(“许可证”)获得许可; 除非遵守许可证,否则您不得使用此文件。 获得许可证的副本,
您可以在http://www.apache.org/licenses/LICENSE-2.0
除非适用法律要求或书面同意,软件 根据许可证分发是在“按原样”的基础上分发的, 没有任何明示或暗示的保证或条件。 请参阅许可证以获取特定语言的管理权限和 许可证下的限制。
2djs
JavaScript library for 2-dimensional array.
- Install
- API
constructor
get()
stat()
clear()
rowSize()
columnSize()
at(rowPosition, columnPosition)
row(position)
column(position)
rows()
columns()
firstRow()
firstColumn()
lastRow()
lastColumn()
add(twoDimensionalArray)
addRow(row)
addColumn(column)
isMember(item)
- License
Install
npm install --save 2djs
or,
yarn add 2djs
API
constructor
import TwoDimensionalArray from '2djs';
const items = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
];
const array = new TwoDimensionalArray(items);
get()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.get(); // [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12] ]
stat()
console.log(array.stats());
{
rowSize: 3,
columnSize: 4
};
clear()
array.clear(); // []
rowSize()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.rowSize(); // 3
columnSize()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.columnSize(); // 4
at(rowPosition, columnPosition)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.at(0, 0); // 1
array.at(2, 2); // 11
array.at(10000, 0); // null
row(position)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.row(0); // [1, 2, 3, 4]
array.row(2); // [9, 10, 11, 12]
column(position)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.column(0); // [1, 5, 9]
array.column(2); // [3, 7, 11]
rows()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.rows(); // [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ]
columns()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.columns(); // [ [ 1, 5, 9 ], [ 2, 6, 10 ], [ 3, 7, 11 ], [ 4, 8, 12 ] ]
firstRow()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.firstRow(); // [1, 2, 3, 4]
firstColumn()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.firstColumn(); // [1, 5, 9]
lastRow()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.lastRow(); // [9, 10, 11, 12]
lastColumn()
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.lastColumn(); // [4, 8, 12]
add(twoDimensionalArray)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
const arr = [ [13, 14, 15, 16], [17, 18, 19, 20] ];
array.add(arr); // [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11, 12 ], [ 13, 14, 15, 16 ], [ 17, 18, 19, 20 ] ]
addRow(row)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.addRow([13, 14, 15, 16]); // [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11, 12 ], [ 13, 14, 15, 16 ] ]
addColumn(column)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.addColumn([2, -1, 1]); // [ [ 1, 2, 3, 4, 2 ], [ 5, 6, 7, 8, -1 ], [ 9, 10, 11, 12, 1 ] ]
isMember(item)
const items = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ];
const array = new TwoDimensionalArray(items);
array.isMember(1); // true
array.isMember(1000); // false
License
Copyright (c) 2020 kenju
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.