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.78 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.77 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.76 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.75 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.74 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.73 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.72 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.71 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.70 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.69 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.68 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.67 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.66 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.65 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.64 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.63 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.62 tracks/ecmascript/exercises/transpose/example.js