From c11d3febb6da20ef948e214db7821f6661062e78 Mon Sep 17 00:00:00 2001 From: alirmemon37 Date: Wed, 30 Aug 2023 12:36:38 +0530 Subject: [PATCH] GREEN: commands input as in assesment --- chandrayaan.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/chandrayaan.js b/chandrayaan.js index 809ae2c..895f568 100644 --- a/chandrayaan.js +++ b/chandrayaan.js @@ -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 };