Dolf,
пробуйте...
$(function() {
let index = 1,
max = $numBuild,
length = $countBuildings + 1;
const hideCells = _ => document.querySelectorAll("#ex4 tr")
.forEach(({ cells }) => {
[...cells].forEach(({ style }, i) => i && (style.display = i < index || i >= index + max ? "none" : "") )
})
var text = [...document.querySelectorAll('#ex4 tr td:nth-child(2)')].map(({childNodes})=> [...childNodes].slice(-2));
const textMove = index => document.querySelectorAll(`#ex4 tr td:nth-child(${++index})`).forEach((td,i) => td.append(...text[i]))
hideCells();
textMove(index);
$(".scroll-table").on("click", "[data-up]", function() {
index += +this.dataset.up;
index = Math.max(1, Math.min(length - max, index));
hideCells();
textMove(index);
})
});