Move up, right, left and down functions I have some code which moves the users position up, right, down or left depending on the direction entered. 

function up(field, player) {
    player.column = player.column + 1;
    field[player.row][player.column] = 'P'; 
}

function right(field, player) {
    player.row = player.row + 1;
    field[player.row][player.column] = 'P';
}

function down(field, player) {
    player.column = player.column - 1;
    field[player.row][player.column] = 'P';
}

function left(field, player) {
    player.row = player.row - 1;
    field[player.row][player.column] = 'P';
}


The code works fine for what I need, but I was curious if there is a more efficient way of writing the 4 functions above? As in maybe use one function rather than 4?

note
Edge cases will be implemented - if the next position is greater than the dimensions of the field, etc. So I'm not sure if this will impact making it more efficient
How about

function move(field, player, dx, dy) {
    player.column = player.column + dx;
    player.row = player.row + dy;
    field[player.row][player.column] = 'P'; 
}


and instead of calling up(field, player), call move(field, player, 0, -1)? With your input, that would basically be

switch(input) {
case 'up':
    move(field, player, 0, -1);
    break;
case 'right':
    move(field, player, 1, 0);
    break;
case 'left':
    move(field, player, -1, 0);
    break;
case 'down':
    move(field, player, 0, 1);
    break;
}


I assume you'll have more code, like checking if the move is valid, resetting the field at the current player position, etc., which won't be duplicated this way. A more complete example might be

function move(field, player, dx, dy) {
    // Valid move?
    let newColumn = player.column + dx;
    let newRow = player.row + dy;
    if (newColumn &lt; 0 || newColumn &gt;= WIDTH ||
        newRow &lt; 0 || newRow &gt;= HEIGHT)
        return;
    // Player cannot hit wall
    if (field[newRow][newColumn] == 'X')
        return;

    // Make move
    field[player.row][player.column] = ' ';
    player.column = newColumn;
    player.row = newRow;
    field[player.row][player.column] = 'P'; 
}



  Edge cases will be implemented - if the next position is greater than the dimensions of the field, etc. So I'm not sure if this will impact making it more efficient


It might seem unnecessary to verify newColumn when you're making a move in the y (row) direction, but comparisons like that are extremely cheap and you shouldn't be worried about their performance.