Sha256: 15e8ddaa124e39323d43542023a895a1dc0f15f793989ed9645cd247adc55bc1

Contents?: true

Size: 864 Bytes

Versions: 181

Compression:

Stored size: 864 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, ii) => {
      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

181 entries across 181 versions & 1 rubygems

Version Path
trackler-2.1.0.5 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.1.0.4 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.1.0.3 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.1.0.2 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.1.0.1 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.1.0.0 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.55 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.54 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.53 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.52 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.51 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.50 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.49 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.48 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.47 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.46 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.45 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.44 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.43 tracks/ecmascript/exercises/saddle-points/example.js
trackler-2.0.8.42 tracks/ecmascript/exercises/saddle-points/example.js