UNPKG

@rayyamhk/matrix

Version:

A professional, comprehensive and high-performance library for you to manipulate matrices.

27 lines (22 loc) 605 B
"use strict"; var _require = require('../../Error'), SIZE_INCOMPATIBLE = _require.SIZE_INCOMPATIBLE; /** * Generate a matrix from an array with compatible dimensions * @memberof Matrix * @static * @param {Array} arr - Source array * @param {number} row - Row of the matrix * @param {number} col - Column of the matrix * @returns {Matrix} Matrix */ function fromArray(arr, row, col) { if (row * col !== arr.length) { throw new Error(SIZE_INCOMPATIBLE); } return this.generate(row, col, function (i, j) { return arr[i * col + j]; }); } ; module.exports = fromArray;