Last active
August 16, 2018 02:09
-
-
Save renatocassino/d1d1526ec9357c7ce688c7eb8fa5e337 to your computer and use it in GitHub Desktop.
Tutorial 2048 functional
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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