Last active
March 30, 2017 08:20
-
-
Save luc4leone/e4b4290feea8961740f965f476d68ed1 to your computer and use it in GitHub Desktop.
my solution to Watch and Code challenge #1: 'Improving runWithDebugger'
This file contains 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
// my solution | |
// I copied the name of the first parameter from Ben Baik solution because | |
// it's a great choice. Maybe it's redundant because 'runWithDebugger' is | |
// already meaningful. I take no risk: redundant maybe, but superclear! :-) | |
function runWithDebugger(functionToDebug, functionToDebugArgs) { | |
debugger; | |
functionToDebug.apply(null, functionToDebugArgs); | |
} | |
// test 1: function with no parameters | |
function logTenNumbers() { | |
for(var i = 0; i < 10; i++) { | |
console.log(i); | |
} | |
} | |
// test 2: function with 1 parameter | |
function sayHiTo(name) { | |
console.log('hi ' + name); | |
} | |
// test 3: function with 2 parameters | |
function sayFullName(first, last) { | |
console.log(first + ' ' + last); | |
} | |
runWithDebugger(logTenNumbers); // 0 1 2 3 4 5 6 7 8 9 | |
runWithDebugger(sayHiTo, ['pippa']); // 'hi pippa' | |
runWithDebugger(sayFullName, ['gordon', 'zhu']); // 'gordon zhu' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!