Skip to content

Commit

Permalink
GREEN: commands input as in assesment
Browse files Browse the repository at this point in the history
  • Loading branch information
alirmemon37 committed Aug 30, 2023
1 parent 61b5536 commit c11d3fe
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions chandrayaan.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ const apply = (command, state) => {
};

const execute = (commands, state) => {
// commands is an array of commands e.g. ['f', 'b', 'l', 'r', 'u', 'd']

// inital state
let result = state;
for (const cmd of commands.split("")) {

for (const cmd of commands) {
// sent the updated state to the next command
result = apply(cmd, result);
}
return result;
};
}

module.exports = { execute };

0 comments on commit c11d3fe

Please sign in to comment.