Untitled
4 years ago in Plain Text
var TEST = function () {
return {
exec: function (str, rowNum) {
let rtn = '', gap = rowNum * 2 - 2;
if (gap <= 0) { return str; }
const usedIdx = new Map();
for (let i=0; i<rowNum; ++i) {
if (!str[i]) { break; }
rtn += str[i];
usedIdx.set(i, true);
let range = 1, inv = -1;
while(true) {
let ptr = range * gap + i * inv
if (!usedIdx.has(ptr)) {
if (!str[ptr]) { break; }
rtn += str[ptr];
usedIdx.set(ptr, true);
}
inv *= -1;
if (inv === -1) { range++; }
}
}
return rtn;
}
};
}();