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.180 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.179 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.178 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.177 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.176 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.175 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.174 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.173 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.172 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.171 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.170 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.169 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.167 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.166 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.165 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.164 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.163 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.162 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.161 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.160 tracks/ecmascript/exercises/transpose/example.js