Sha256: d34f253f17a750d960f18f59bf1565e53722d1f2334663ce610d6a6ae53f7420
Contents?: true
Size: 860 Bytes
Versions: 215
Compression:
Stored size: 860 Bytes
Contents
function findSaddlePoints(rows, rowMaxs, colMins) { return rows.reduce((saddlePoints, row, rowIndex) => { row.forEach((cell, colIndex) => { if (cell === rowMaxs[rowIndex] && cell === colMins[colIndex]) { saddlePoints.push([rowIndex, colIndex]); } }); return saddlePoints; }, []); } export default class Matrix { constructor(data) { this.rows = []; this.columns = []; data.split(/\n/).map((row) => { this.rows.push(row.trim().split(/\s/).map((cell, jj) => { this.columns[jj] ? this.columns[jj].push(+cell) : this.columns[jj] = [+cell]; return +cell; })); }); const rowMaxs = this.rows.map(row => Math.max.apply(null, row)); const colMins = this.columns.map(col => Math.min.apply(null, col)); this.saddlePoints = findSaddlePoints(this.rows, rowMaxs, colMins); } }
Version data entries
215 entries across 215 versions & 1 rubygems