Skip to content

Instantly share code, notes, and snippets.

@luc4leone
Last active March 30, 2017 08:20
Show Gist options
  • Save luc4leone/e4b4290feea8961740f965f476d68ed1 to your computer and use it in GitHub Desktop.
Save luc4leone/e4b4290feea8961740f965f476d68ed1 to your computer and use it in GitHub Desktop.
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'
@gordonmzhu
Copy link

Nice!

@luc4leone
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment