Skip to content

Instantly share code, notes, and snippets.

@porcoespinho
Last active March 13, 2017 01:03
Show Gist options
  • Save porcoespinho/7f640c178a0aaee69c9642bd536cb227 to your computer and use it in GitHub Desktop.
Save porcoespinho/7f640c178a0aaee69c9642bd536cb227 to your computer and use it in GitHub Desktop.
Luis Vargas version of Improving runWithDebugger #2
// Beasts challenge 1
/**
* Your task is to rewrite runWithDebugger so it can take an optional array
* that contains any arguments you want to pass into the callback function.
You should be able to pass multiple arguments into the array. Here's an example.
function sayFullName(first, last) {
console.log(first + ' ' + last);
}
runWithDebugger(sayFullName, ['gordon', 'zhu']); // 'gordon zhu'
*/
/* Original run with debugger
function runWithDebugger(ourFunction) {
debugger;
ourFunction();
}
*/
// My solution:
function runWithDebugger(ourFunction, inputArray) {
debugger;
ourFunction.apply(null, inputArray);
}
/**
* I use the apply method in my solution...
* The apply() method calls a function with a given this value and arguments
* provided as an array (or an array-like object).
* Syntax: fun.apply(thisArg, [argsArray])
* Note: if the method is a function in non-strict mode code,
* null and undefined will be replaced with the global object
* Example:
function sayFullName(first, last) {
console.log(first + ' ' + last);
}
sayFullName.apply(null,['luis','vargas']);
*/
@gordonmzhu
Copy link

gordonmzhu commented Mar 12, 2017

Hey Luis. Can you save this file as a JavaScript file so that you get syntax highlighting? Also make sure to format consistently. For example, the indentation in line 23 is unusual.

@porcoespinho
Copy link
Author

Hi Gordon, thanks for the feedback!

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