Skip to content

Instantly share code, notes, and snippets.

View raffaele-abramini's full-sized avatar
⛰️

Raffaele Abramini raffaele-abramini

⛰️
View GitHub Profile
function convert(s: string, numRows: number): string {
const chars = Array.from(s);
const rows: string[][] = [];
const I = 2;
chars.forEach((char, index) => {
const factor = (numRows * 2 - I) || 1;
const cycle = Math.floor(index / factor);
const phase = index - factor * cycle;
const isDiagonal = phase > (numRows - 1);