javascript - 我在 Matrix 元素构造函数中输入什么来填充矩阵?
问题描述
export class Matrix {
constructor(...m) {
console.log(...m);
this.m = new Array(16).fill(0).splice(0, m.length, ...m);
}
toArray() {
return [...this.m];
}
toString() {
return `(${this.m.join(',')})`;
}
negate(){
}
}
const mtrx = new Matrix(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
这是老师给我的构造函数,怎么调用这个构造函数,把元素放进去呢?...m 表示任何数组,但我无法在线找到正确的语法。如果我称它为我是如何得到一个充满 0 的矩阵的。
解决方案
有效的只是简单地这样做:
this.m = new Array(16).fill(0);
this.m.splice(0, m.length, ...m);
推荐阅读
- html - 将 wordpress 页眉和页脚添加到 HTML 页面
- azure - 备份和还原 Azure SQL 数据库架构
- linux - Systemd 获取看门狗超时的原因
- pdf - Google Drive PDF Viewer 有时无法加载 pdf
- reactjs - ReactJS Jest Tesing - fireEvent.click() 没有触发按钮
- python-3.x - Python 3.6 邻接矩阵:如何以更好的方式获取它
- docker - 在 docker 的 Gitlab 管道中出现错误“jq:找不到命令”
- javascript - React 和 Redux:401 未经授权的错误 POST API 请求
- powershell - 对于 CSV 中的每个名称写入每个输出文件,替换单词 00000 来命名例如 1 个输出 Henry 等等
- javascript - 为什么我集成了 javascript-driver 却没有全局 neo4j 对象?