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.159 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.158 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.157 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.156 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.155 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.154 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.153 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.152 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.151 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.150 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.149 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.148 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.147 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.146 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.145 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.144 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.143 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.142 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.141 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.2.1.140 tracks/ecmascript/exercises/saddle-points/example.js