Last active
November 23, 2016 10:25
-
-
Save Ankirama/949391b7d583949f4533d6df94a4c8fd to your computer and use it in GitHub Desktop.
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
function command1(params) { | |
if (params.length > 0) { | |
console.log('command1 --> ', params); | |
} | |
return 0; | |
} | |
function command2(params) { | |
if (params.length > 0) { | |
console.log('command2 --> ', params); | |
} | |
return 0; | |
} | |
function command3(params) { | |
if (params.length > 0) { | |
console.log('command3 --> ', params); | |
} | |
return 0; | |
} | |
let dictionnary = { | |
"command1": command1, | |
"command2": command2, | |
"command3": command3 | |
}; | |
function useCommand(cmd, params) { | |
if (dictionnary.hasOwnProperty(cmd)) { | |
return dictionnary[cmd](params); | |
} else { | |
console.log("Command not found, you must specify a valid one..."); | |
return 1; | |
} | |
} | |
// Tests | |
useCommand('toto', []); // message + retourne 1 | |
useCommand('command1', []); // rien + retourne 0 | |
useCommand('command2', [1, 2, 3]); // affiche [1, 2, 3] + retourne 0 | |
useCommand('command4', [1, 2, 3]); // message + retourne 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment