给定行数和列数,写3个函数分别输出如下的二维数组(假设给的行数是5,列数是4):
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
1 6 11 16
2 7 12 17
3 8 13 18
4 9 14 19
5 10 15 20
1 10 11 20
2 9 12 19
3 8 13 18
4 7 14 17
5 6 15 16
这个怎么做啊?
(function(window, document) {
let sorts = function(option) {
this._init(option);
};
sorts.prototype._init = function(option) {
this.arrs = option.arr;
this.rows = option.rows;
this.cols = option.cols;
this._create();
};
sorts.prototype._create = function(option) {
let nums = 0;
for (let i = 0; i < this.rows; i++) {
document.write('<br>');
for (let j = 0; j < this.cols; j++) {
if (this.arrs[nums]) {
document.writeln(this.arrs[nums]);
nums++;
}
}
}
};
window.sorts = sorts
})(window, document);
new sorts({
rows: 5,
cols: 4,
arr: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20']
});这个类型不能算。
丛从绿草
pardon110
随时随地看视频慕课网APP