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.119 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.118 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.117 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.116 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.115 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.114 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.113 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.111 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.110 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.109 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.108 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.107 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.106 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.105 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.104 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.103 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.102 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.101 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.100 tracks/ecmascript/exercises/transpose/example.js
trackler-2.2.1.99 tracks/ecmascript/exercises/transpose/example.js