Sha256: 2372ea4179872cb995b3e98d123e23b67b36228a47a4e8b0809852a77af89cb7

Contents?: true

Size: 489 Bytes

Versions: 117

Compression:

Stored size: 489 Bytes

Contents

function trimTrailingUndefined(array) {
  const trailingUndefinedCount = [...array].reverse().findIndex(x => x !== undefined);
  return array.slice(0, array.length - trailingUndefinedCount);
}

export default function transpose(input) {
  const maxCol = Math.max(0, ...(input.map(row => row.length)));
  return [...Array(maxCol).keys()].map(col =>
    trimTrailingUndefined(input.map((_v, row) => input[row][col]))
      .map(charOrUndefined => charOrUndefined || ' ')
      .join(''));
}

Version data entries

117 entries across 117 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.158 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.157 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.156 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.155 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.154 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.153 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.152 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.151 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.150 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.149 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.148 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.147 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.146 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.145 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.144 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.143 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.142 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.141 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.140 tracks/ecmascript/exercises/transpose/example.js