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.98 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.97 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.96 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.95 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.94 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.93 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.92 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.91 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.90 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.89 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.88 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.87 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.86 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.85 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.84 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.83 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.82 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.81 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.80 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.79 tracks/ecmascript/exercises/transpose/example.js