my solution to Watch and Code challenge #1: 'Improving runWithDebugger'
// 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'