Last active
August 7, 2018 16:49
-
-
Save renatocassino/cce62e558148c211a1fcf36e44c080c9 to your computer and use it in GitHub Desktop.
2048-addNumber.js
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
// @param 2 in format [column:int, line:int] | |
// @param number with default value 2 | |
const addNumber = (board, [columnIndex, lineIndex], number=2) => { | |
const line = board[columnIndex]; // Get line to change | |
const newLine = [ | |
...line.slice(0, lineIndex), // Getting all values before index to change | |
number, // Add number to array | |
...line.slice(lineIndex + 1, line.length), // Getting all values after index to change | |
]; | |
return [ // Creating new board | |
...board.slice(0, columnIndex), // Lines before index | |
newLine, // New line | |
...board.slice(columnIndex + 1, board.length), // Lines after index | |
]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment