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

Version Path
trackler-2.2.1.180 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.179 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.178 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.177 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.176 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.175 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.174 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.173 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.172 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.171 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.170 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.169 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.167 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.166 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.165 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.164 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.163 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.162 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.161 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.160 tracks/ecmascript/exercises/saddle-points/example.js