Skip to content

Instantly share code, notes, and snippets.

@renatocassino
Last active August 16, 2018 02:09
Show Gist options
  • Save renatocassino/d1d1526ec9357c7ce688c7eb8fa5e337 to your computer and use it in GitHub Desktop.
Save renatocassino/d1d1526ec9357c7ce688c7eb8fa5e337 to your computer and use it in GitHub Desktop.
Tutorial 2048 functional
const printBoard = (board) => {
const format = (n, stringSize) => {
const size = n.toString().length;
return ' '.repeat(stringSize - spaces) + n + ' ';
}
const textToPrint = board.map((column, idxLine) => {
const line = column.map((_, idxColumn) => format(board[idxColumn][idxLine]));
return line.join('|');
});
console.log('-'.repeat(4*5+5));
console.log(textToPrint.join("\n"));
console.log('-'.repeat(4*5+5));
return board;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment